Help! Weird behavior calling end()
Hi all!
First of all...this is more a request for help than an issue.
Client OS: AmazonLinux:2 SFTP Server OS: Windows (something) Versions:
- ssh2-sftp-client Version: 9.0.4
- node: 16.15.0
- v8: 9.4.146.24-node.20
Description: in brief, SOMETIMES my code get stuck when it try to disconnect from sftp server. This is very weird because, sometimes it works fine, disconnects and finish, but sometimes it get stuck. It doesn't throw errors and I can't define a common pattern, so I don't know where or what to debug.
Sample of code
const client = new SshSftpClient();
client.on("error", (err: Error) => {
console.debug(`sftp connection error: ${err}`);
});
client.on("close", () => {
console.debug("sftp connection closed");
});
client.on("end", () => {
console.debug("sftp connection end");
});
try {
await client.connect({<common_params_for_connection>});
// some operations, like put
await client.end();
}
catch(error) {
// handle error
}
The logs for when it works ok are like this:
SFTP: Inbound: Received STATUS (id:191, 0, ""Success"")
Outbound: Sending DISCONNECT (11)
Socket ended
CLIENT[sftp]: end endListener - ignoring handled error
CLIENT[sftp]: Global end event: Ignoring expected and handled event
Socket closed
CLIENT[sftp]: end: Connection closed
CLIENT[sftp]: end closeListener - ignoring handled error
CLIENT[sftp]: Global close event: Ignoring expected and handled event
And when it get stuck are just this:
SFTP: Inbound: Received STATUS (id:74, 0, ""Success"")
Outbound: Sending DISCONNECT (11)
I know that probably the information is not much, but I don't have any additional info to add.
So any ideas? Something that I can try/change?
TIA
You need to update to v10.0.3.
The version you are running had known problems with handling unexpected close of connection by remote server. This was fixed in later versions.
Hi @theophilusx , and thanks for your response. I'll try updating the version, but just in case, is there any other way to force close the connection to the server, but end() method? Thanks
No, the only way to end a connencttion is by calling end().
Ok. Thank you again. I'll give a try to the new version and let you know about results.
Best Regards