sanketbajoria / ssh2-promise

ssh with promise/async await and typescript support
https://www.npmjs.com/package/ssh2-promise
MIT License
148 stars 24 forks source link

Promises are not resolved/rejected when connection is lost during operation #30

Open jeffrson opened 5 years ago

jeffrson commented 5 years ago

This may sound similar to https://github.com/sanketbajoria/ssh2-promise/issues/27, but it's not.

While the former hands off control to streams, there are more direct issues with commands like "rmdir" (just an example which happened to me...).

I have written an SFTP server with NodeJs/SSH2. I use SSH2Promises to, say, remove a directory. Yes, it was a bug that the server crashed when I was trying to do that. But there are other circumstances which could lead to disconnection during operations. The problem here is, that the promise that's returned from sftp.rmdir(directory) is never resolved or rejected when this happens.

Now I could try to listen for 'ssh' events again and continue somehow (have another promise and use Promise.race) - but this would still keep the original promise pending for ever.

Any idea how to "cancel" the promise?

jeffrson commented 2 years ago

Looks like closing sftp connection in "ssh" disconnected event releases the promise by rejecting.

jeffrson commented 2 years ago

Uh - no. Must 've been wrong test case.

Promise is not released unfortunately.