Skip to content

Commit

Permalink
Fix connection.destroy() on pool connection creating sequences
Browse files Browse the repository at this point in the history
fixes #1291
  • Loading branch information
rfk authored and dougwilson committed Nov 27, 2015
1 parent e6b075e commit 179660f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes.md
Expand Up @@ -6,6 +6,7 @@ you spot any mistakes.

## HEAD

* Fix `connection.destroy()` on pool connection creating sequences #1291
* Fix reading password from MySQL URL that has bare colon #1278
* Handle MySQL servers not closing TCP connection after QUIT -> OK exchange #1277
* Minor SqlString Date to string performance improvement #1233
Expand Down
2 changes: 1 addition & 1 deletion lib/PoolConnection.js
Expand Up @@ -43,8 +43,8 @@ PoolConnection.prototype.end = function () {
};

PoolConnection.prototype.destroy = function () {
Connection.prototype.destroy.apply(this, arguments);
this._removeFromPool(this);
return Connection.prototype.destroy.apply(this, arguments);
};

PoolConnection.prototype._removeFromPool = function _removeFromPool() {
Expand Down
27 changes: 27 additions & 0 deletions test/unit/pool/test-connection-destroy.js
@@ -0,0 +1,27 @@
var assert = require('assert');
var common = require('../../common');
var Connection = common.Connection;
var pool = common.createPool({port: common.fakeServerPort});

var server = common.createFakeServer();

server.listen(common.fakeServerPort, function (err) {
assert.ifError(err);

pool.getConnection(function (err, connection) {
assert.ifError(err);
assert.notEqual(connection.state, 'disconnected');

connection.on('enqueue', function () {
throw new Error('Unexpected sequence enqueued after connection destroy');
});

connection.destroy();
assert.equal(connection.state, 'disconnected');

pool.end(function (err) {
assert.ifError(err);
server.destroy();
});
});
});

0 comments on commit 179660f

Please sign in to comment.