Fix queued checkout after a connection failure (#111)

* Test queued checkout after a connection failure

Co-authored-by: Johannes Würbach <johannes.wuerbach@googlemail.com>

* Fix queued checkout after a connection failure

Co-authored-by: Johannes Würbach <johannes.wuerbach@googlemail.com>
This commit is contained in:
Charmander 2018-12-11 10:53:00 -08:00 committed by Brian C
parent 4b9669eaa7
commit 7ef3f4aa4a
2 changed files with 26 additions and 0 deletions

View File

@ -226,6 +226,10 @@ class Pool extends EventEmitter {
if (timeoutHit) {
err.message = 'Connection terminated due to connection timeout'
}
// this client wont be released, so move on immediately
this._pulseQueue()
cb(err, undefined, NOOP)
} else {
this.log('new client connected')

View File

@ -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)
})
})
})
})
})