Skip to content
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

How to capture connection errors in the SFTP read stream #130

Open
dvlato opened this issue Apr 9, 2019 · 1 comment
Open

How to capture connection errors in the SFTP read stream #130

dvlato opened this issue Apr 9, 2019 · 1 comment

Comments

@dvlato
Copy link

dvlato commented Apr 9, 2019

I have some code that can access a number of different network/file resources, including a SFTP server. This code gets a Stream from any of those different resources and then pipes it doing some processing.

Our problem is that for ssh2-sftp-client, if the connection drops the stream does not fail. We have added keepAliveInterval to have an error event when the connection drops, but that event does not make our stream fail. Are we doing anything incorrectly? We would like the stream to fail so we can capture the error, is that possible? Otherwise, what would be your recommended approach to make sure the download() method below fails?

Sample pseudocode where client is an abstraction over ssh2 sftpclient (with some other implementations):

async download() {
await client.connect(params);
const stream = await client.getReadStream(name);
return new Promise((resolve, reject) => {
stream
.on('error', err => {
LOG.error(Error {err}, Full stack: ${err.});
reject(err);
})
.pipe(unzipper.Parse())...
}

@dvlato
Copy link
Author

dvlato commented Jun 11, 2019

We solved this by propagating the 'ssh level' errors to users of the 'client' object... Quite unfortunate but we haven't found any other way.

We'd still love to have the stream fail when the connection is closed/lost as it is the case for all the other libraries we are using to upload to different services.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant