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

fix: catch and re-reject failed promise from sftp() #72

Merged
merged 1 commit into from
Jun 5, 2022

Conversation

jeffrson
Copy link
Contributor

@jeffrson jeffrson commented May 1, 2022

I had a hard time with occasional crashs of my app due to rejection in
https://github.com/sanketbajoria/ssh2-promise/blob/master/src/sshConnection.ts#L80

It could happen, if the server closes the connection (for whatever reason) before sftp subsystem is "ready", maybe during completion of handshake. The error from ssh2 is "No response from server", originated in ssh2\lib\client.js:764:19.

Turns out, the rejected promise is not handled in
https://github.com/sanketbajoria/ssh2-promise/blob/master/src/sftp.ts#L29
so the app crashs with "unhandled promise" exception.

My fix catches the rejected async promise and uses the error for rejecting the current promise.

Now, the error can be handled by the application:

sftp.readdir.then().catch()

@sanketbajoria sanketbajoria merged commit 2600c87 into sanketbajoria:master Jun 5, 2022
@sanketbajoria
Copy link
Owner

thanks @jeffrson for fixing it up...

@jeffrson due to time constraints. i am looking out for maintainer. If you like to be maintainer of this project. Please let me know.

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

Successfully merging this pull request may close these issues.

2 participants