fix: ssh tunnel keep-alive not working properly

This commit is contained in:
Fabio Di Stasio 2023-10-28 19:09:19 +02:00
parent 3c2e2be40f
commit debc1da289
3 changed files with 18 additions and 6 deletions

View File

@ -55,7 +55,7 @@ export default (connections: {[key: string]: antares.Client}) => {
port: conn.sshPort ? conn.sshPort : 22, port: conn.sshPort ? conn.sshPort : 22,
privateKey: conn.sshKey ? fs.readFileSync(conn.sshKey).toString() : null, privateKey: conn.sshKey ? fs.readFileSync(conn.sshKey).toString() : null,
passphrase: conn.sshPassphrase, passphrase: conn.sshPassphrase,
keepaliveInterval: conn.sshKeepAliveInterval ?? conn.sshKeepAliveInterval*1000 keepaliveInterval: conn.sshKeepAliveInterval ? conn.sshKeepAliveInterval*1000 : null
}; };
} }
@ -137,7 +137,7 @@ export default (connections: {[key: string]: antares.Client}) => {
port: conn.sshPort ? conn.sshPort : 22, port: conn.sshPort ? conn.sshPort : 22,
privateKey: conn.sshKey ? fs.readFileSync(conn.sshKey).toString() : null, privateKey: conn.sshKey ? fs.readFileSync(conn.sshKey).toString() : null,
passphrase: conn.sshPassphrase, passphrase: conn.sshPassphrase,
keepaliveInterval: conn.sshKeepAliveInterval ?? conn.sshKeepAliveInterval*1000 keepaliveInterval: conn.sshKeepAliveInterval ? conn.sshKeepAliveInterval*1000 : null
}; };
} }

View File

@ -168,7 +168,10 @@ export class MySQLClient extends BaseClient {
dbConfig.port = tunnel.localPort; dbConfig.port = tunnel.localPort;
} }
catch (err) { catch (err) {
if (this._ssh) this._ssh.close(); if (this._ssh) {
this._ssh.close();
this._ssh.closeTunnel();
}
throw err; throw err;
} }
} }
@ -187,7 +190,10 @@ export class MySQLClient extends BaseClient {
this._connection.end(); this._connection.end();
clearInterval(this._keepaliveTimer); clearInterval(this._keepaliveTimer);
this._keepaliveTimer = undefined; this._keepaliveTimer = undefined;
if (this._ssh) this._ssh.close(); if (this._ssh) {
this._ssh.close();
this._ssh.closeTunnel();
}
} }
async getConnection () { async getConnection () {

View File

@ -180,7 +180,10 @@ export class PostgreSQLClient extends BaseClient {
dbConfig.port = tunnel.localPort; dbConfig.port = tunnel.localPort;
} }
catch (err) { catch (err) {
if (this._ssh) this._ssh.close(); if (this._ssh) {
this._ssh.close();
this._ssh.closeTunnel();
}
throw err; throw err;
} }
} }
@ -236,7 +239,10 @@ export class PostgreSQLClient extends BaseClient {
this._connection.end(); this._connection.end();
clearInterval(this._keepaliveTimer); clearInterval(this._keepaliveTimer);
this._keepaliveTimer = undefined; this._keepaliveTimer = undefined;
if (this._ssh) this._ssh.close(); if (this._ssh) {
this._ssh.close();
this._ssh.closeTunnel();
}
} }
private async keepAlive () { private async keepAlive () {