Skip to content

Commit a6f641e

Browse files
Lee Symesbrianc
Lee Symes
authored andcommitted
Only release client once on an error. (#3)
Prevent `generic-pool` error when releasing a client with an error. Fixes #2
1 parent e38cfe0 commit a6f641e

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

Diff for: index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ Pool.prototype.connect = function (cb) {
6060
this.log('acquire client')
6161

6262
client.release = function (err) {
63+
delete client.release
6364
if (err) {
64-
this.log('release client. error:', err)
65+
this.log('destroy client. error:', err)
6566
this.pool.destroy(client)
67+
} else {
68+
this.log('release client')
69+
this.pool.release(client)
6670
}
67-
this.log('release client')
68-
delete client.release
69-
this.pool.release(client)
7071
}.bind(this)
7172

7273
if (cb) {

Diff for: test/index.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,18 @@ describe('pool', function () {
8989
}))
9090

9191
it('recovers from all errors', co.wrap(function * () {
92-
var pool = new Pool({ poolSize: 9 })
92+
var pool = new Pool({
93+
poolSize: 9,
94+
log: function (str, level) {
95+
// Custom logging function to ensure we are not causing errors or warnings
96+
// inside the `generic-pool` library.
97+
if (level === 'error' || level === 'warn') {
98+
expect().fail('An error or warning was logged from the generic pool library.\n' +
99+
'Level: ' + level + '\n' +
100+
'Message: ' + str + '\n')
101+
}
102+
}
103+
})
93104
var count = 0
94105

95106
while (count++ < 30) {

0 commit comments

Comments
 (0)