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

How to get the retry count? #69

Open
rehanvdm opened this issue Nov 5, 2021 · 1 comment
Open

How to get the retry count? #69

rehanvdm opened this issue Nov 5, 2021 · 1 comment

Comments

@rehanvdm
Copy link

rehanvdm commented Nov 5, 2021

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:

  1. Connected to the internet
  2. Connect SSH + Tunnels, test and it works.
  3. Disconnect from the internet
  4. ?? Need some event to know that we are retrying the connection ??
  5. Connect to the internet
  6. Test and it still works

If anyone has any advice or help, would be much appreciated.

@rehanvdm
Copy link
Author

rehanvdm commented Nov 9, 2021

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

if (this.config.reconnect && this.__retries <= this.config.reconnectTries && this.__err != null && this.__err.level != "client-authentication" && this.__err.code != 'ENOTFOUND') {

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.

reject(this.__err);

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.

rehanvdm pushed a commit to rehanvdm/ssh2-promise that referenced this issue Nov 9, 2021
…bajoria#69

- Add this.close() after connection could not be retried
- Commit the generated JS files because will install direct from GitHub

sanketbajoria#69
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