question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Node can crash while doing a put because of missing 'error' handler

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:17 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
theophilusxcommented, Oct 16, 2019

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.

1reaction
AndrewLanecommented, Oct 15, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Let It Crash: Best Practices for Handling Node.js Errors on ...
When a JavaScript error is not properly handled, an uncaughtException is emitted. These suggest the programmer has made an error, and they ...
Read more >
Best Practices for Node.js Error-handling - Toptal
The best way to deal with these errors is to crash immediately and restart gracefully with an automatic restarter like PM2—the reason being...
Read more >
Why does my app keep crashing through a faulty error handler ...
I guess you forgot to wrap your code inside a try-catch block. Since you are throwing an error, but it is never caught...
Read more >
A Comprehensive Guide To Error Handling In Node.js
An error in Node.js is any instance of the Error object. ... it becomes an uncaught exception, which may cause your application to...
Read more >
Error handling in node.js. Even with the most experienced…
Another example could be missing to put a comma or colon in the object. Whenever any of these errors are encountered in your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found