Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not return broken clients to the pool (#2083)
* Prevent requeuing a broken client If a client is not queryable, the pool should prevent requeuing instead of strictly enforcing errors to be propagated back to it. * Write tests for change * Use node 13.6 in travis Some weird behavior changed w/ async iteration in node 13.7...I'm not sure if this was an unintentional break or not but it definitely diverges in behavior from node 12 and earlier versions in node 13...so for now going to run tests on 13.6 to unblock the tests from running while I track this down. * Update packages/pg-pool/test/releasing-clients.js Co-Authored-By: Charmander <~@charmander.me> * Update .travis.yml Co-authored-by: Johannes Würbach <johannes.wuerbach@googlemail.com> Co-authored-by: Charmander <~@charmander.me>
- Loading branch information
1 parent
3f6760c
commit 727f1a0
Showing
3 changed files
with
65 additions
and
3 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
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,54 @@ | ||
const Pool = require('../') | ||
|
||
const expect = require('expect.js') | ||
const net = require('net') | ||
|
||
describe('releasing clients', () => { | ||
it('removes a client which cannot be queried', async () => { | ||
// make a pool w/ only 1 client | ||
const pool = new Pool({ max: 1 }) | ||
expect(pool.totalCount).to.eql(0) | ||
const client = await pool.connect() | ||
expect(pool.totalCount).to.eql(1) | ||
expect(pool.idleCount).to.eql(0) | ||
// reach into the client and sever its connection | ||
client.connection.end() | ||
|
||
// wait for the client to error out | ||
const err = await new Promise((resolve) => client.once('error', resolve)) | ||
expect(err).to.be.ok() | ||
expect(pool.totalCount).to.eql(1) | ||
expect(pool.idleCount).to.eql(0) | ||
|
||
// try to return it to the pool - this removes it because its broken | ||
client.release() | ||
expect(pool.totalCount).to.eql(0) | ||
expect(pool.idleCount).to.eql(0) | ||
|
||
// make sure pool still works | ||
const { rows } = await pool.query('SELECT NOW()') | ||
expect(rows).to.have.length(1) | ||
await pool.end() | ||
}) | ||
|
||
it('removes a client which is ending', async () => { | ||
// make a pool w/ only 1 client | ||
const pool = new Pool({ max: 1 }) | ||
expect(pool.totalCount).to.eql(0) | ||
const client = await pool.connect() | ||
expect(pool.totalCount).to.eql(1) | ||
expect(pool.idleCount).to.eql(0) | ||
// end the client gracefully (but you shouldn't do this with pooled clients) | ||
client.end() | ||
|
||
// try to return it to the pool | ||
client.release() | ||
expect(pool.totalCount).to.eql(0) | ||
expect(pool.idleCount).to.eql(0) | ||
|
||
// make sure pool still works | ||
const { rows } = await pool.query('SELECT NOW()') | ||
expect(rows).to.have.length(1) | ||
await pool.end() | ||
}) | ||
}) |