Skip to content

Commit

Permalink
fix: ssh tunnel keep-alive not working properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Oct 28, 2023
1 parent 3c2e2be commit debc1da
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/ipc-handlers/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default (connections: {[key: string]: antares.Client}) => {
port: conn.sshPort ? conn.sshPort : 22,
privateKey: conn.sshKey ? fs.readFileSync(conn.sshKey).toString() : null,
passphrase: conn.sshPassphrase,
keepaliveInterval: conn.sshKeepAliveInterval ?? conn.sshKeepAliveInterval*1000
keepaliveInterval: conn.sshKeepAliveInterval ? conn.sshKeepAliveInterval*1000 : null
};
}

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

Expand Down
10 changes: 8 additions & 2 deletions src/main/libs/clients/MySQLClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ export class MySQLClient extends BaseClient {
dbConfig.port = tunnel.localPort;
}
catch (err) {
if (this._ssh) this._ssh.close();
if (this._ssh) {
this._ssh.close();
this._ssh.closeTunnel();
}
throw err;
}
}
Expand All @@ -187,7 +190,10 @@ export class MySQLClient extends BaseClient {
this._connection.end();
clearInterval(this._keepaliveTimer);
this._keepaliveTimer = undefined;
if (this._ssh) this._ssh.close();
if (this._ssh) {
this._ssh.close();
this._ssh.closeTunnel();
}
}

async getConnection () {
Expand Down
10 changes: 8 additions & 2 deletions src/main/libs/clients/PostgreSQLClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ export class PostgreSQLClient extends BaseClient {
dbConfig.port = tunnel.localPort;
}
catch (err) {
if (this._ssh) this._ssh.close();
if (this._ssh) {
this._ssh.close();
this._ssh.closeTunnel();
}
throw err;
}
}
Expand Down Expand Up @@ -236,7 +239,10 @@ export class PostgreSQLClient extends BaseClient {
this._connection.end();
clearInterval(this._keepaliveTimer);
this._keepaliveTimer = undefined;
if (this._ssh) this._ssh.close();
if (this._ssh) {
this._ssh.close();
this._ssh.closeTunnel();
}
}

private async keepAlive () {
Expand Down

0 comments on commit debc1da

Please sign in to comment.