ssh2-sftp-client: Node can crash while doing a put because of missing 'error' handler

Hello,

We are seeing the possibility for a crash of node when doing a put.

Here is the stack trace:

Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:111:27)
...
Emitted 'error' event at:
    at Socket.<anonymous> (/usr/src/app/node_modules/ssh2/lib/client.js:307:10)
    at Socket.emit (events.js:198:13)
    at Socket.EventEmitter.emit (domain.js:448:20)
...
    at process._tickCallback (internal/process/next_tick.js:63:19)
error Command failed with exit code 1.
error Command failed.
Exit code: 1

In terms of things we have looked at, we see that the SFTPWrapper will emit an error: https://github.com/mscdex/ssh2/blob/master/lib/SFTPWrapper.js#L15-L16

Do we need to add an error handler to the sftp object here in addition to the stream?

https://github.com/theophilusx/ssh2-sftp-client/blob/master/src/index.js#L449-L453

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (17 by maintainers)

Most upvoted comments

Sorry, I should have included more code earlier. I’m calling that transferFile method this way:

  try {
    log.info(`Transferring ${fileName}...`);
    await transferFile(connectionParams, fileName, sftpPath, file);
    log.info(`Successfully transferred ${fileName}.`);
    // ...
  } catch (err) {
    log.error(`Failure transferring ${fileName}: ${err.message}`);
    // ...
  }

And what we are seeing during the crash is that the first Transferring... log is output, but then nothing (we see evidence of a crash right afterwards). We don’t see the log that indicates a success, nor do we see the log that indicates a failure.

Forgot to mention that if you are able to make any progress, I am more than happy to accept pull requests which address the issue.