Skip to content

Commit 9f99156

Browse files
committed
Fix pool.query not invoking callback on connection error
fixes #872
1 parent 76012f6 commit 9f99156

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

Changes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ This file is a manually maintained list of changes for each release. Feel free
44
to add your changes here when sending pull requests. Also send corrections if
55
you spot any mistakes.
66

7+
## HEAD
8+
9+
* Fix `pool.query` not invoking callback on connection error #872
10+
711
## v2.4.0 (2014-07-13)
812

913
* Add code `POOL_NOEXIST` in PoolCluster error #846

lib/Pool.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ Pool.prototype.query = function (sql, values, cb) {
169169
}
170170

171171
this.getConnection(function (err, conn) {
172-
if (err) return cb && cb(err);
172+
if (err) {
173+
var cb = query._callback;
174+
cb && cb(err);
175+
return;
176+
}
173177

174178
// Release connection based off event
175179
query.once('end', function() {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var assert = require('assert');
2+
var common = require('../../common');
3+
var pool = common.createPool({port: common.fakeServerPort});
4+
var server = common.createFakeServer();
5+
6+
server.listen(common.fakeServerPort, function (err) {
7+
assert.ifError(err);
8+
9+
pool.query('SELECT 1', function (err, rows) {
10+
assert.ok(err, 'got error');
11+
assert.equal(err.code, 'ER_HOST_NOT_PRIVILEGED');
12+
assert.equal(err.fatal, true);
13+
server.destroy();
14+
});
15+
});
16+
17+
server.on('connection', function (conn) {
18+
conn.deny('You suck.', common.Errors.ER_HOST_NOT_PRIVILEGED);
19+
});

0 commit comments

Comments
 (0)