mscdex / ssh2-streams

SSH2 and SFTP client/server protocol streams for node.js
MIT License
204 stars 144 forks source link

Piping sftp readStream to sftp writeStream - no error when client disconnects #127

Open jeffrson opened 5 years ago

jeffrson commented 5 years ago

Hi, I'm copying files via sftp from one server to another simply by piping a readStream to writeStream. Actually I'm using ssh2-promise, but afaict, it simply wraps ssh2-streams methods.

Unfortunately, it seems copying hangs forever, when (say) the destination server disappears. Debug output says

DEBUG: Outgoing: Writing CHANNEL_CLOSE (0) and later DEBUG: Outgoing: Writing REQUEST_FAILURE

every 15 seconds. When the source server disappears instead, I don't see a channel close, but outgoing write fails with the same DEBUG message.

Furthermore, when I want to cancel a copy task, closing ssh2 connection does not seem to stop/error the streams.

How should I handle these cases?

jeffrson commented 5 years ago

Well, nevertheless it might be an ssh2-promise issue (see linked issue).

jeffrson commented 5 years ago

Hmmm - is it a bug, that not the readStream emits the error, but SSH2.Client?

mscdex commented 5 years ago

If there are outstanding requests for an sftp session when it's cleaned up, errors are passed to the requests' callbacks, which should in turn emit errors on the stream.