Skip to content

Commit f64dbad

Browse files
committed
Fix un-catchable error from poolCluster.remove
1 parent 16b7c39 commit f64dbad

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

lib/PoolCluster.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,20 @@ PoolCluster.prototype.of = function(pattern, selector) {
116116
return this._namespaces[key];
117117
};
118118

119-
PoolCluster.prototype.remove = function(pattern) {
119+
PoolCluster.prototype.remove = function remove(pattern) {
120120
var foundNodeIds = this._findNodeIds(pattern);
121121

122122
for (var i = 0; i < foundNodeIds.length; i++) {
123123
var node = this._getNode(foundNodeIds[i]);
124124
var index = this._serviceableNodeIds.indexOf(node.id);
125+
125126
if (index !== -1) {
126127
this._serviceableNodeIds.splice(index, 1);
127128
delete this._nodes[node.id];
128129

129130
this._clearFindCaches();
130131

131-
node.pool.end();
132+
node.pool.end(_noop);
132133
}
133134
}
134135
};

test/unit/pool-cluster/test-remove-by-name.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ server.listen(common.fakeServerPort, function (err) {
3333
cluster.remove('SLAVE1');
3434
cluster.remove('SLAVE2');
3535

36-
server._server.close();
36+
cluster.end(function (err) {
37+
assert.ifError(err);
38+
server.destroy();
39+
});
3740
});
3841
});
3942
});

test/unit/pool-cluster/test-remove-by-pattern.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ server.listen(common.fakeServerPort, function (err) {
2525

2626
cluster.remove('SLAVE*');
2727

28-
server._server.close();
28+
cluster.end(function (err) {
29+
assert.ifError(err);
30+
server.destroy();
31+
});
2932
});
3033
});
3134
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var assert = require('assert');
2+
var common = require('../../common');
3+
var cluster = common.createPoolCluster();
4+
var server = common.createFakeServer();
5+
6+
var poolConfig = common.getTestConfig({port: common.fakeServerPort});
7+
cluster.add('SLAVE1', poolConfig);
8+
cluster.add('SLAVE2', poolConfig);
9+
10+
server.listen(common.fakeServerPort, function (err) {
11+
assert.ifError(err);
12+
13+
var pool = cluster.of('SLAVE*', 'ORDER');
14+
15+
pool.getConnection(function (err, connection) {
16+
assert.ifError(err);
17+
assert.strictEqual(connection._clusterId, 'SLAVE1');
18+
19+
connection.release();
20+
server.destroy();
21+
cluster.remove('SLAVE*');
22+
23+
cluster.end(assert.ifError);
24+
});
25+
});

0 commit comments

Comments
 (0)