Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Node to exit if the pool is idle (#2568)
Based on the suggestion from #2078. This adds ref/unref methods to the Connection and Client classes and then uses them to allow the process to exit if all of the connections in the pool are idle. This behavior is controlled by the allowExitOnIdle flag to the Pool constructor; it defaults to the old behavior.
- Loading branch information
Brian Crowell
committed
Jul 27, 2021
1 parent
aedaa59
commit 684cd09
Showing
5 changed files
with
74 additions
and
0 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
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,16 @@ | ||
// This test is meant to be spawned from idle-timeout.js | ||
if (module === require.main) { | ||
const allowExitOnIdle = process.env.ALLOW_EXIT_ON_IDLE === '1' | ||
const Pool = require('../index') | ||
|
||
const pool = new Pool({ idleTimeoutMillis: 200, ...(allowExitOnIdle ? { allowExitOnIdle: true } : {}) }) | ||
pool.query('SELECT NOW()', (err, res) => console.log('completed first')) | ||
pool.on('remove', () => { | ||
console.log('removed') | ||
done() | ||
}) | ||
|
||
setTimeout(() => { | ||
pool.query('SELECT * from generate_series(0, 1000)', (err, res) => console.log('completed second')) | ||
}, 50) | ||
} |
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
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
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