Skip to content
This repository was archived by the owner on Dec 30, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
22 changes: 22 additions & 0 deletions test/error-handling.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'
const net = require('net')
const co = require('co')
const expect = require('expect.js')

Expand Down Expand Up @@ -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)
})
})
})
})
})