Skip to content

Commit 6474bf5

Browse files
committed
Do not remove connections with non-fatal errors from the pool
1 parent 379e59e commit 6474bf5

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

Changes.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ you spot any mistakes.
77
## HEAD
88

99
* Delay implied connect until after `.query` argument validation
10+
* Do not remove connections with non-fatal errors from the pool
1011
* Error early if `callback` argument to `.query` is not a function #1060
1112
* Lazy-load modules from many entry point; reduced memory use
1213

lib/PoolConnection.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ function PoolConnection(pool, options) {
1414
// the connection to end as well, thus we only need to watch for the end event
1515
// and we will be notified of disconnects.
1616
this.on('end', this._removeFromPool);
17-
this.on('error', this._removeFromPool);
17+
this.on('error', function (err) {
18+
if (err.fatal) {
19+
this._removeFromPool();
20+
}
21+
});
1822
}
1923

2024
PoolConnection.prototype.changeUser = function changeUser(options, callback) {

test/unit/pool/test-query-error.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var assert = require('assert');
2+
var common = require('../../common');
3+
var pool = common.createPool({
4+
connectionLimit : 1,
5+
port : common.fakeServerPort,
6+
waitForConnections : false
7+
});
8+
9+
var server = common.createFakeServer();
10+
11+
server.listen(common.fakeServerPort, function (err) {
12+
assert.ifError(err);
13+
14+
pool.getConnection(function (err, conn) {
15+
assert.ifError(err);
16+
17+
conn.query('SELECT INVALID');
18+
conn.on('error', function () {
19+
pool.getConnection(function (err) {
20+
assert.ok(err);
21+
assert.equal(err.message, 'No connections available.');
22+
23+
conn.release();
24+
pool.end(function (err) {
25+
assert.ifError(err);
26+
server.destroy();
27+
});
28+
});
29+
});
30+
});
31+
});

0 commit comments

Comments
 (0)