Skip to content

Commit 5632485

Browse files
committed
Return last error when PoolCluster exhausts connection retries
fixes #818
1 parent f03bf56 commit 5632485

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

Changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ you spot any mistakes.
1111
* Clone connection config for new pool connections
1212
* Default `connectTimeout` to 2 minutes
1313
* Reject unauthorized SSL connections (use `ssl.rejectUnauthorized` to override) #816
14+
* Return last error when PoolCluster exhausts connection retries #818
1415
* Throw on unknown SSL profile name #817
1516
* User newer TLS functions when available #809
1617

lib/PoolCluster.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ PoolCluster.prototype._increaseErrorCount = function(node) {
136136

137137
this.emit('remove', node.id);
138138
}
139+
140+
return true;
139141
}
142+
143+
return false;
140144
};
141145

142146
PoolCluster.prototype._decreaseErrorCount = function(node) {
@@ -150,9 +154,9 @@ PoolCluster.prototype._getConnection = function(node, cb) {
150154

151155
node.pool.getConnection(function (err, connection) {
152156
if (err) {
153-
self._increaseErrorCount(node);
157+
var removed = self._increaseErrorCount(node);
154158

155-
if (self._canRetry) {
159+
if (!removed && self._canRetry) {
156160
return cb(null, 'retry');
157161
} else {
158162
return cb(err);

test/integration/pool/test-cluster.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ function createPoolCluster(clusterConfig, poolConfig) {
221221
cluster.of('*', 'RR').getConnection(function (err, connection) {
222222
cluster.end();
223223

224-
assert.ok(err === null);
224+
assert.ifError(err);
225225
assert.equal(connection._clusterId, 'CORRECT');
226226

227227
assert.equal(removedNodeId, 'ERROR');
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var assert = require('assert');
2+
var common = require('../../common');
3+
var cluster = common.createPoolCluster({
4+
canRetry : true,
5+
removeNodeErrorCount : 5
6+
});
7+
var server = common.createFakeServer();
8+
9+
var connCount = 0;
10+
var poolConfig = common.getTestConfig({port: common.fakeServerPort});
11+
cluster.add('MASTER', poolConfig);
12+
13+
server.listen(common.fakeServerPort, function(err) {
14+
assert.ifError(err);
15+
16+
cluster.getConnection('MASTER', function(err, conn){
17+
assert.ok(err);
18+
assert.equal(err.code, 'ER_HOST_NOT_PRIVILEGED');
19+
assert.equal(err.fatal, true);
20+
assert.equal(connCount, 5);
21+
server.destroy();
22+
});
23+
});
24+
25+
server.on('connection', function(incomingConnection) {
26+
var errno = 1130; // ER_HOST_NOT_PRIVILEGED
27+
connCount += 1;
28+
incomingConnection.deny('You suck.', errno);
29+
});

0 commit comments

Comments
 (0)