Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for closeTunnel() hangs #89

Open
dubdia opened this issue Sep 26, 2024 · 0 comments
Open

Suggestion for closeTunnel() hangs #89

dubdia opened this issue Sep 26, 2024 · 0 comments

Comments

@dubdia
Copy link

dubdia commented Sep 26, 2024

Hello, i had the problem that calling closeTunnel(..) would hang until all sockets were closed.
Maybe closeTunnel should itself close the connections?

This could be done like this, when the connections are established we keep track of the sockets: (in file sshConnection.ts)

server = net.createServer().on("connection", (socket) => {
            this.activeTunnels[tunnelConfig.name].sockets.push(socket);
            this.connect().then(() => {...

And the closeTunnel method could look like this (the close sockets part is new):

closeTunnel(name?: string): Promise<void> {
   if (name && this.activeTunnels[name]) {
     return new Promise((resolve, reject) => {
       var tunnel = this.activeTunnels[name];
       this.emit(SSHConstants.CHANNEL.TUNNEL, SSHConstants.STATUS.BEFOREDISCONNECT, { tunnelConfig: tunnel });

       // subscribe to close event
       tunnel.server.close((err) => {
         this.emit(SSHConstants.CHANNEL.TUNNEL, SSHConstants.STATUS.DISCONNECT, {
           tunnelConfig: this.activeTunnels[name],
         });
         delete this.activeTunnels[name];
         if (err) {
           reject(err);
         } else {
           resolve();
         }
       });

       // close sockets 
       if(tunnel.sockets) {
         for(let socket of tunnel.sockets) {
           socket.destroySoon();
         }
       }
     });
   } else if (!name) {
     var tunnels = Object.keys(this.activeTunnels).map((key) => this.closeTunnel(key));
     return Promise.all(tunnels).then(() => {});
   }
 }
}

what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant