From 4a55be3ae98d7ecfe425b6f3e1f67745aec427c6 Mon Sep 17 00:00:00 2001 From: Charmander <~@charmander.me> Date: Mon, 3 Dec 2018 00:29:58 -0800 Subject: [PATCH 1/2] Test queued checkout after a connection failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Johannes Würbach --- test/error-handling.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/error-handling.js b/test/error-handling.js index 9435dd7..1c84889 100644 --- a/test/error-handling.js +++ b/test/error-handling.js @@ -1,4 +1,5 @@ 'use strict' +const net = require('net') const co = require('co') const expect = require('expect.js') @@ -143,4 +144,25 @@ describe('pool error handling', function () { return pool.end() })) }) + + it('should continue with queued items after a connection failure', (done) => { + const closeServer = net.createServer((socket) => { + socket.destroy() + }).unref() + + closeServer.listen(() => { + const pool = new Pool({ max: 1, port: closeServer.address().port }) + pool.connect((err) => { + expect(err).to.be.an(Error) + expect(err.message).to.be('Connection terminated unexpectedly') + }) + pool.connect((err) => { + expect(err).to.be.an(Error) + expect(err.message).to.be('Connection terminated unexpectedly') + closeServer.close(() => { + pool.end(done) + }) + }) + }) + }) }) From ce87c92210b363251a2a63f1181834dae9ebbb82 Mon Sep 17 00:00:00 2001 From: Charmander <~@charmander.me> Date: Mon, 3 Dec 2018 00:57:47 -0800 Subject: [PATCH 2/2] Fix queued checkout after a connection failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Johannes Würbach --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index ab74209..2ccbbe7 100644 --- a/index.js +++ b/index.js @@ -226,6 +226,10 @@ class Pool extends EventEmitter { if (timeoutHit) { err.message = 'Connection terminated due to connection timeout' } + + // this client won’t be released, so move on immediately + this._pulseQueue() + cb(err, undefined, NOOP) } else { this.log('new client connected')