Skip to content

Commit c7f761b

Browse files
committed
Fix pool.query not emitting connection errors
fixes #941
1 parent c244a56 commit c7f761b

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
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` streaming interface not emitting connection errors #941
10+
711
## v2.5.2 (2014-10-10)
812

913
* Fix receiving large text fields #922

lib/Pool.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ Pool.prototype.query = function (sql, values, cb) {
182182

183183
this.getConnection(function (err, conn) {
184184
if (err) {
185-
var cb = query._callback;
186-
cb && cb(err);
185+
query.on('error', function () {});
186+
query.end(err);
187187
return;
188188
}
189189

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
var query = pool.query('SELECT 1');
10+
11+
query.on('error', function (err) {
12+
assert.ok(err, 'got error');
13+
assert.equal(err.code, 'ER_HOST_NOT_PRIVILEGED');
14+
assert.equal(err.fatal, true);
15+
server.destroy();
16+
});
17+
});
18+
19+
server.on('connection', function (conn) {
20+
conn.deny('You suck.', common.Errors.ER_HOST_NOT_PRIVILEGED);
21+
});

0 commit comments

Comments
 (0)