-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: release pending pool connections on error (#632)
* release pending pool connections on error * changeset * simplify try/catch * oops - remove package-lock.json --------- Co-authored-by: Michael Nigh <[email protected]> Co-authored-by: Gajus Kuizinas <[email protected]>
- Loading branch information
1 parent
c415b16
commit 48263cd
Showing
4 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"slonik": patch | ||
--- | ||
|
||
Fix: release pending pool connections on error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/slonik/src/integration.test/lost-connection.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* eslint-disable no-console */ | ||
|
||
import { createPool, sql } from '..'; | ||
import { startTestContainer } from './termination.test'; | ||
import test from 'ava'; | ||
import { execSync } from 'node:child_process'; | ||
|
||
/** | ||
* @see https://github.com/gajus/slonik/issues/631 | ||
*/ | ||
test('releases failed connections', async (t) => { | ||
t.timeout(10_000); | ||
|
||
try { | ||
const output = execSync('docker --version', { encoding: 'utf8' }); | ||
console.log('Docker CLI is available:', output.trim()); | ||
} catch { | ||
console.log('Skipper the test. Docker CLI is not available.'); | ||
|
||
return; | ||
} | ||
|
||
const { dsn, terminate } = await startTestContainer(); | ||
|
||
const pool = await createPool(dsn, { | ||
connectionRetryLimit: 1, | ||
connectionTimeout: 500, | ||
maximumPoolSize: 1, | ||
}); | ||
|
||
terminate(); | ||
|
||
const isConnectionAvailable = async () => { | ||
try { | ||
await pool.connect((connection) => { | ||
return connection.oneFirst(sql.unsafe`SELECT NOW()`); | ||
}); | ||
return true; | ||
} catch { | ||
// do nothing | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
t.deepEqual( | ||
[await isConnectionAvailable(), await isConnectionAvailable()], | ||
[false, false], | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters