From 6fa430adf68013a9d0a093031f56dd741bdc0299 Mon Sep 17 00:00:00 2001 From: Fabio Di Stasio Date: Thu, 29 Dec 2022 13:04:20 +0100 Subject: [PATCH] fix: ssh connection closed after idle time, fixes #425 --- package-lock.json | 19 +++++++++++++++++++ package.json | 1 + src/main/libs/clients/MySQLClient.ts | 8 +++++++- src/main/libs/clients/PostgreSQLClient.ts | 6 +++++- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index a383a084..5cf8a68e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -52,6 +52,7 @@ "@types/marked": "~4.0.7", "@types/node": "~17.0.23", "@types/pg": "~8.6.5", + "@types/ssh2": "~1.11.6", "@typescript-eslint/eslint-plugin": "~5.18.0", "@typescript-eslint/parser": "~5.18.0", "@vue/compiler-sfc": "~3.2.33", @@ -2703,6 +2704,15 @@ "@types/node": "*" } }, + "node_modules/@types/ssh2": { + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@types/ssh2/-/ssh2-1.11.6.tgz", + "integrity": "sha512-8Mf6bhzYYBLEB/G6COux7DS/F5bCWwojv/qFo2yH/e4cLzAavJnxvFXrYW59iKfXdhG6OmzJcXDasgOb/s0rxw==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/verror": { "version": "1.10.6", "resolved": "https://registry.npmjs.org/@types/verror/-/verror-1.10.6.tgz", @@ -17985,6 +17995,15 @@ "@types/node": "*" } }, + "@types/ssh2": { + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@types/ssh2/-/ssh2-1.11.6.tgz", + "integrity": "sha512-8Mf6bhzYYBLEB/G6COux7DS/F5bCWwojv/qFo2yH/e4cLzAavJnxvFXrYW59iKfXdhG6OmzJcXDasgOb/s0rxw==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/verror": { "version": "1.10.6", "resolved": "https://registry.npmjs.org/@types/verror/-/verror-1.10.6.tgz", diff --git a/package.json b/package.json index da7ad91b..b5c209c9 100644 --- a/package.json +++ b/package.json @@ -161,6 +161,7 @@ "@types/marked": "~4.0.7", "@types/node": "~17.0.23", "@types/pg": "~8.6.5", + "@types/ssh2": "~1.11.6", "@typescript-eslint/eslint-plugin": "~5.18.0", "@typescript-eslint/parser": "~5.18.0", "@vue/compiler-sfc": "~3.2.33", diff --git a/src/main/libs/clients/MySQLClient.ts b/src/main/libs/clients/MySQLClient.ts index 969ebc5f..6e2c6363 100644 --- a/src/main/libs/clients/MySQLClient.ts +++ b/src/main/libs/clients/MySQLClient.ts @@ -147,7 +147,13 @@ export class MySQLClient extends AntaresCore { if (this._params.ssh) { try { - this._ssh = new SSH2Promise({ ...this._params.ssh }); + if (this._params.ssh.password === '') delete this._params.ssh.password; + + this._ssh = new SSH2Promise({ + ...this._params.ssh, + keepaliveInterval: 20000, + debug: process.env.NODE_ENV !== 'production' ? (s) => console.log(s) : null + }); const tunnel = await this._ssh.addTunnel({ remoteAddr: this._params.host, diff --git a/src/main/libs/clients/PostgreSQLClient.ts b/src/main/libs/clients/PostgreSQLClient.ts index 1bac1037..eddc3e22 100644 --- a/src/main/libs/clients/PostgreSQLClient.ts +++ b/src/main/libs/clients/PostgreSQLClient.ts @@ -162,7 +162,11 @@ export class PostgreSQLClient extends AntaresCore { if (this._params.ssh) { try { - this._ssh = new SSH2Promise({ ...this._params.ssh }); + this._ssh = new SSH2Promise({ + ...this._params.ssh, + keepaliveInterval: 20000, + debug: process.env.NODE_ENV !== 'production' ? (s) => console.log(s) : null + }); const tunnel = await this._ssh.addTunnel({ remoteAddr: this._params.host,