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') 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) + }) + }) + }) + }) })