-
Notifications
You must be signed in to change notification settings - Fork 200
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
Seeing unhandled error and nodejs crash #562
Comments
Get rid of the promise and just use the API directly. There is no need
to use the promise or add an error listener, it is all taken care of
within the library itself. Just wrap the calls to the library within a
try/catch and call await sftp.connect() and await sftp.get() or await
sftp.put() or whatever you need and then await sftp.end(). Also look at
the README for the lib as this outlines how error events are handled and
what you need to do if the default setup does not meet your
requirements and the limitations wrt handling errors. Main thing is get rid of the call to new Promise as it is
unnecessary and is just causing unnecesary additional complexity.
FYI the reason you have and uncaught exception is because your error
handler runs outside the try/catch block. This is one of the major
challenges associated with wanting to wrap and event based API inside an
async promise based API. There use to be a section about the problems
with usinmg try/catch and event emitters in the node documentation - not
sure if it is still there as I've not checked the most recent docs.
|
Thanks for the help |
I have another doubt @theophilusx it looks like for this below code
I am still seeing the hanging issue which causes the partial file download issue is that issue expected because i am using the connect in promise? but this happens randomly I thought this was fixed with latest release. Adding another question with this I am using ssh-rsa based auth and even the download speed is to slow for this can authentication can impact network speed i am reading the rsa key using fs.readFileSync |
@theophilusx also, I tried your example code but looks like for sftp.get() with passing stream we are seeing unhandled error event nodejs crash for 11.0.0 and nodejs v18.20.4 i downgraded the version to 9.1.0 and now i dont see the crash anymore. But sftp.fastget() seems to be working
This also throws Emitted 'error' event on ReadStream instance at: when the file doesnt exist in server it just crash the node process |
I tried to switch from v11.0.0 to 9.1.0 and looks like unhandled error is gone now node version 18.20.4 and this unhandled error is seeing only for .get() not for fastGet() |
Hi, I am using the latest ssh2-sftp-client library
And this is what I am trying to do
I got uncaught error handler err with error
readtimeout
withCONNRESET
messageno response from server
i saw the log SFTP connection error: which is from the.on
event listener and Error during SFTP connection: from catch part and it crashed the nodejs application itself not sure what I should do hereAnd also before the code was like this:
and the ssh2-sftp-client version 9.x.x and during the connection reset i didnt saw crash and it just logged properly the error
The text was updated successfully, but these errors were encountered: