Skip to content

Commit 8684641

Browse files
committed
refactor(database): ConnectionPool class to handle null client and pool ended state
1 parent b1d5275 commit 8684641

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/database/ConnectionPool.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class ConnectionPool {
1010
this._pool = this.initializePool(connectionString);
1111
}
1212
async connect(): Promise<boolean> {
13-
let client;
13+
let client: PoolClient | null = null;
1414
try {
1515
client = await this._pool.connect();
1616
logger.info('Database connection successful');
@@ -37,7 +37,6 @@ export class ConnectionPool {
3737
return false;
3838
}
3939
} finally {
40-
// Release client only if it was successfully acquired
4140
if (client) {
4241
client.release();
4342
}
@@ -77,7 +76,7 @@ export class ConnectionPool {
7776
});
7877
}
7978
async reinitializePool() {
80-
if (this._pool) {
79+
if (this._pool && !this._pool.ended) {
8180
await this._pool.end();
8281
}
8382
const newConnectionString = this.getConnectionString();

0 commit comments

Comments
 (0)