Open rehanvdm opened 3 years ago
Related to #23
The reason I couldn't find a way was because of how the event emitter does not reregister events when it creates the new connection using the retry logic. I couldn't find/see a way around this, the sshConnection.ts class to callback to the index.ts to close the connection, remove the event listeners and then reattach them for when it creates the new connection in the retry logic here https://github.com/sanketbajoria/ssh2-promise/blob/5e3674da5bdf0e4c39a2df5e98b4a5acd771ee8e/src/sshConnection.ts#L280
I am disabling the retry logic, forking this repo and then adding a this.close();
just above the reject. I could for the life of me also not catch that.
This closes the connection but still non of the original events are fired, but in my use case that monitors the local ports this is fine. As soon as I see the port is available and my program thinks it is in use, then I know something closed it and I must retry.
My application requires knowledge of when a SSH Connection + Tunnels are retrying.
The close and disconnect events do not fire and I have spent a lot of time trying to figure out how to get either an event or a flag by inspecting private variables on the class. But it shows connected every time. My procedure:
If anyone has any advice or help, would be much appreciated.