Skip to content

Commit 61a8b67

Browse files
committed
fix: add timeout to releasePromise in connection destroy path
releasePromise (e.g. DISCARD ALL) had no timeout in internalDestroy(), causing connections to stay in PENDING_DESTROY indefinitely when the database is unreachable. These connections count toward maximumPoolSize, blocking the pool from creating new connections.
1 parent 9714266 commit 61a8b67

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

.changeset/slick-falcons-cheer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"slonik": patch
3+
---
4+
5+
add timeout to releasePromise in connection destroy path

packages/driver/src/factories/createDriverFactory.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,17 +262,20 @@ export const createDriverFactory = (setup: DriverSetup): DriverFactory => {
262262

263263
clearIdleTimeout();
264264

265-
if (activeQueryPromise) {
265+
// activeQueryPromise and releasePromise are mutually exclusive
266+
// (release throws if a query is active). Either one can hang if the
267+
// database is unreachable (e.g. DISCARD ALL during release), causing
268+
// the connection to stay in PENDING_DESTROY and count toward
269+
// maximumPoolSize, which blocks the pool from creating new connections.
270+
const pendingOperation = activeQueryPromise ?? releasePromise;
271+
272+
if (pendingOperation) {
266273
await Promise.race([
267274
delay(driverConfiguration.gracefulTerminationTimeout),
268-
activeQueryPromise,
275+
pendingOperation,
269276
]);
270277
}
271278

272-
if (releasePromise) {
273-
await releasePromise;
274-
}
275-
276279
isDestroyed = true;
277280

278281
clientEventEmitter.emit('destroy');

0 commit comments

Comments
 (0)