From 236e98be1dcc0e4b836359e51a3300590700f860 Mon Sep 17 00:00:00 2001 From: Karen <64801825+karenc-bq@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:38:00 -0700 Subject: [PATCH] fix: end called when no connection has been established yet (#256) --- mysql/lib/client.ts | 6 ++++++ pg/lib/client.ts | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/mysql/lib/client.ts b/mysql/lib/client.ts index 67ec6ec8..ac2a060a 100644 --- a/mysql/lib/client.ts +++ b/mysql/lib/client.ts @@ -211,6 +211,12 @@ export class AwsMySQLClient extends AwsClient { } async end() { + if (!this.isConnected || !this.targetClient?.client) { + // No connections has been initialized. + // This might happen if end is called in a finally block when an error occurred while initializing the first connection. + return; + } + const hostInfo: HostInfo | null = this.pluginService.getCurrentHostInfo(); const result = await this.pluginManager.execute( this.pluginService.getCurrentHostInfo(), diff --git a/pg/lib/client.ts b/pg/lib/client.ts index 3db2c58f..0cb1252e 100644 --- a/pg/lib/client.ts +++ b/pg/lib/client.ts @@ -192,6 +192,11 @@ export class AwsPGClient extends AwsClient { } async end() { + if (!this.isConnected || !this.targetClient?.client) { + // No connections has been initialized. + // This might happen if end is called in a finally block when an error occurred while initializing the first connection. + return; + } const hostInfo: HostInfo | null = this.pluginService.getCurrentHostInfo(); const result = await this.pluginManager.execute( hostInfo,