Skip to content

Commit 5f09c1c

Browse files
committed
Add code POOL_ENQUEUELIMIT to error reaching queueLimit
1 parent 2978c34 commit 5f09c1c

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

Changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ you spot any mistakes.
66

77
## HEAD
88

9+
* Add code `POOL_ENQUEUELIMIT` to error reaching `queueLimit`
910
* Add `enqueue` event to protocol and connection #381
1011
* Blacklist unsupported connection flags #881
1112
* Make only column names enumerable in `RowDataPacket` #549 #895

lib/Pool.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,7 @@ Pool.prototype.getConnection = function (cb) {
5858
});
5959
}
6060

61-
if (this.config.queueLimit && this._connectionQueue.length >= this.config.queueLimit) {
62-
return cb(new Error('Queue limit reached.'));
63-
}
64-
65-
if (cb && process.domain)
66-
cb = process.domain.bind(cb);
67-
this._connectionQueue.push(cb);
61+
this._enqueueCallback(cb);
6862
};
6963

7064
Pool.prototype.acquireConnection = function acquireConnection(connection, cb) {
@@ -190,6 +184,25 @@ Pool.prototype.query = function (sql, values, cb) {
190184
return query;
191185
};
192186

187+
Pool.prototype._enqueueCallback = function _enqueueCallback(callback) {
188+
189+
if (this.config.queueLimit && this._connectionQueue.length >= this.config.queueLimit) {
190+
process.nextTick(function () {
191+
var err = new Error('Queue limit reached.');
192+
err.code = 'POOL_ENQUEUELIMIT';
193+
callback(err);
194+
});
195+
return;
196+
}
197+
198+
// Bind to domain, as dequeue will likely occur in a different domain
199+
var cb = process.domain
200+
? process.domain.bind(callback)
201+
: callback;
202+
203+
this._connectionQueue.push(cb);
204+
};
205+
193206
Pool.prototype._purgeConnection = function _purgeConnection(connection) {
194207
var pool = this;
195208

test/unit/pool/test-queue-limit.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ server.listen(common.fakeServerPort, function (err) {
3030
assert.ifError(err);
3131
assert.ok(error);
3232
assert.equal(error.message, 'Queue limit reached.');
33+
assert.equal(error.code, 'POOL_ENQUEUELIMIT');
3334
server.destroy();
3435
});
3536
});

0 commit comments

Comments
 (0)