Skip to content

Commit

Permalink
fix: close all connections in pool.end() (#633)
Browse files Browse the repository at this point in the history
* fix: close all connections in pool.end()

* chore: add changeset
  • Loading branch information
mikeroelens authored Aug 1, 2024
1 parent 4f5f762 commit c415b16
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-chicken-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"slonik": major
---

fix: close all connections in pool.end(). Previously a subset idleConnections would hang until idleTimeout was reached
6 changes: 5 additions & 1 deletion packages/slonik/src/factories/createConnectionPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ export const createConnectionPool = ({
// e.g. "waits for all connections to be established before attempting to terminate the pool" test
await delay(0);

await Promise.all(connections.map((connection) => connection.destroy()));
// Make a copy of `connections` array as items are removed from it during the map iteration.
// If `connections` array is used directly, the loop will skip some items.
await Promise.all(
[...connections].map((connection) => connection.destroy()),
);
};

const acquire = async () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/slonik/src/helpers.test/createIntegrationTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ export const createIntegrationTests = (

const pool = await createPool(t.context.dsn, {
driverFactory,
idleTimeout: 500,
idleTimeout: 'DISABLE_TIMEOUT',
maximumPoolSize: 5,
});

Expand Down Expand Up @@ -968,8 +968,6 @@ export const createIntegrationTests = (

await pool.end();

await delay(600);

t.deepEqual(pool.state(), {
acquiredConnections: 0,
idleConnections: 0,
Expand Down

0 comments on commit c415b16

Please sign in to comment.