Skip to content

Commit 7ef3f4a

Browse files
charmanderjohanneswuerbach
authored andcommitted
Fix queued checkout after a connection failure (brianc#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>
1 parent 4b9669e commit 7ef3f4a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

index.js

+4
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ class Pool extends EventEmitter {
226226
if (timeoutHit) {
227227
err.message = 'Connection terminated due to connection timeout'
228228
}
229+
230+
// this client won’t be released, so move on immediately
231+
this._pulseQueue()
232+
229233
cb(err, undefined, NOOP)
230234
} else {
231235
this.log('new client connected')

test/error-handling.js

+22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict'
2+
const net = require('net')
23
const co = require('co')
34
const expect = require('expect.js')
45

@@ -143,4 +144,25 @@ describe('pool error handling', function () {
143144
return pool.end()
144145
}))
145146
})
147+
148+
it('should continue with queued items after a connection failure', (done) => {
149+
const closeServer = net.createServer((socket) => {
150+
socket.destroy()
151+
}).unref()
152+
153+
closeServer.listen(() => {
154+
const pool = new Pool({ max: 1, port: closeServer.address().port })
155+
pool.connect((err) => {
156+
expect(err).to.be.an(Error)
157+
expect(err.message).to.be('Connection terminated unexpectedly')
158+
})
159+
pool.connect((err) => {
160+
expect(err).to.be.an(Error)
161+
expect(err.message).to.be('Connection terminated unexpectedly')
162+
closeServer.close(() => {
163+
pool.end(done)
164+
})
165+
})
166+
})
167+
})
146168
})

0 commit comments

Comments
 (0)