ssh2-sftp-client: uncaughtException Error: connect: read ECONNRESET
My server crashes when the sftp server is not available, while creating a connection.
Im using:
NodeJS: v20.13.1 OS: Windows 10 ssh2: 1.15.0 ssh2-sftp-client: 10.0.3
protected async doPoll(): Promise<{ url: string; success: boolean; error: string | null }> {
try {
await using sftp = await this.createConnection(); // connect & disconnect
return { url: this.config.url, success: true, error: null };
} catch (error: unknown) {
this.logger.error('Polling-Request failed: ', error);
return { url: this.config.url, success: false, error: error.toString() };
}
}
protected async createConnection(options?: Client.ConnectOptions) {
const sftpClient = new Client(this.config.name);
const connectionInfo = options || (await this.getSFTPConnectionInfo(this.config, this.logger));
const sftpWrapper = await sftpClient.connect(connectionInfo);
if (sftpWrapper === undefined) {
throw new Error('SFTP connection could not be established!');
}
return {
client: sftpClient,
[Symbol.asyncDispose]: async () => {
try {
await sftpClient?.end();
} catch (error: unknown) {
// if there is no SFTP connection available, we have no connection to close anyway, so we only log the other errors
if (hasMessage(error) && error.message !== 'end: No SFTP connection available') {
this.logger.error(error.message, error);
}
}
}
};
}
ERROR:
uncaught Error: connect: read ECONNRESET at uncaughtException Error: connect: read ECONNRESET
at Client.fn (C:\prj\mylib\dist\apps\server\node_modules\ssh2-sftp-client\src\utils.js:20:22)
at Client.emit (node:events:531:35)
at Socket.<anonymous> (C:\prj\mylib\dist\apps\server\node_modules\ssh2\lib\client.js:807:12)
at emitErrorNT (node:internal/streams/destroy:169:8)
at emitErrorCloseNT (node:internal/streams/destroy:128:3)
at processTicksAndRejections (node:internal/process/task_queues:82:21)
C:\prj\mylib\dist\apps\server\node_modules\ssh2-sftp-client\src\utils.js:20
const newError = new Error(`${name}: ${err.message}`);
^
Error: connect: read ECONNRESET
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (8 by maintainers)
As this module now does not throw any errors inside global event listeners and only does reject inside promise related listeners, any remaining problems with catching errors are outside control of this module and therefore not relevant so closing this issue as being resolved in the new version.