Skip to content

Commit 286a5bc

Browse files
SamBergeronluin
authored andcommitted
feat: report error on Sentinel connection refused (#445) (#446)
* Report error on Sentinel connection refused * Removed duplicate line, oops * Errors emitted instead of called back * Spacing * Fixed error reporting to event reporting
1 parent 539fe41 commit 286a5bc

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/connectors/sentinel_connector.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ SentinelConnector.prototype.check = function (info) {
2828
return true;
2929
};
3030

31-
SentinelConnector.prototype.connect = function (callback) {
31+
SentinelConnector.prototype.connect = function (callback, eventEmitter) {
3232
this.connecting = true;
3333
this.retryAttempts = 0;
3434

@@ -48,20 +48,24 @@ SentinelConnector.prototype.connect = function (callback) {
4848
if (_this.currentPoint === _this.sentinels.length) {
4949
_this.currentPoint = -1;
5050

51+
var error;
5152
var retryDelay;
5253
if (typeof _this.options.sentinelRetryStrategy === 'function') {
5354
retryDelay = _this.options.sentinelRetryStrategy(++_this.retryAttempts);
5455
}
56+
5557
if (typeof retryDelay !== 'number') {
5658
debug('All sentinels are unreachable and retry is disabled, emitting error...');
57-
var error = 'All sentinels are unreachable.';
59+
error = 'All sentinels are unreachable.';
5860
if (lastError) {
5961
error += ' Last error: ' + lastError.message;
6062
}
6163
return callback(new Error(error));
6264
}
6365
debug('All sentinels are unreachable. Retrying from scratch after %d', retryDelay);
66+
error = 'All sentinels are unreachable, retrying...';
6467
setTimeout(connectToNext, retryDelay);
68+
eventEmitter('error', new Error(error));
6569
return;
6670
}
6771

@@ -76,11 +80,13 @@ SentinelConnector.prototype.connect = function (callback) {
7680
callback(null, _this.stream);
7781
} else if (err) {
7882
debug('failed to connect to sentinel %s:%s because %s', endpoint.host, endpoint.port, err);
83+
eventEmitter('sentinelError', new Error('failed to connect to sentinel '+endpoint.host+':'+endpoint.port+' because '+err));
7984
lastError = err;
8085
connectToNext();
8186
} else {
8287
debug('connected to sentinel %s:%s successfully, but got a invalid reply: %s',
8388
endpoint.host, endpoint.port, resolved);
89+
eventEmitter('sentinelError', new Error('connected to sentinel '+endpoint.host+':'+endpoint.port+' successfully, but got a invalid reply: '+resolved));
8490
connectToNext();
8591
}
8692
});

lib/redis.js

+2
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ Redis.prototype.connect = function (callback) {
311311
};
312312
_this.once(CONNECT_EVENT, connectionConnectHandler);
313313
_this.once('close', connectionCloseHandler);
314+
}, function(type, err) {
315+
_this.silentEmit(type, err);
314316
});
315317
}.bind(this)).nodeify(callback);
316318
};

0 commit comments

Comments
 (0)