@@ -28,7 +28,7 @@ SentinelConnector.prototype.check = function (info) {
28
28
return true ;
29
29
} ;
30
30
31
- SentinelConnector . prototype . connect = function ( callback ) {
31
+ SentinelConnector . prototype . connect = function ( callback , eventEmitter ) {
32
32
this . connecting = true ;
33
33
this . retryAttempts = 0 ;
34
34
@@ -48,20 +48,24 @@ SentinelConnector.prototype.connect = function (callback) {
48
48
if ( _this . currentPoint === _this . sentinels . length ) {
49
49
_this . currentPoint = - 1 ;
50
50
51
+ var error ;
51
52
var retryDelay ;
52
53
if ( typeof _this . options . sentinelRetryStrategy === 'function' ) {
53
54
retryDelay = _this . options . sentinelRetryStrategy ( ++ _this . retryAttempts ) ;
54
55
}
56
+
55
57
if ( typeof retryDelay !== 'number' ) {
56
58
debug ( 'All sentinels are unreachable and retry is disabled, emitting error...' ) ;
57
- var error = 'All sentinels are unreachable.' ;
59
+ error = 'All sentinels are unreachable.' ;
58
60
if ( lastError ) {
59
61
error += ' Last error: ' + lastError . message ;
60
62
}
61
63
return callback ( new Error ( error ) ) ;
62
64
}
63
65
debug ( 'All sentinels are unreachable. Retrying from scratch after %d' , retryDelay ) ;
66
+ error = 'All sentinels are unreachable, retrying...' ;
64
67
setTimeout ( connectToNext , retryDelay ) ;
68
+ eventEmitter ( 'error' , new Error ( error ) ) ;
65
69
return ;
66
70
}
67
71
@@ -76,11 +80,13 @@ SentinelConnector.prototype.connect = function (callback) {
76
80
callback ( null , _this . stream ) ;
77
81
} else if ( err ) {
78
82
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 ) ) ;
79
84
lastError = err ;
80
85
connectToNext ( ) ;
81
86
} else {
82
87
debug ( 'connected to sentinel %s:%s successfully, but got a invalid reply: %s' ,
83
88
endpoint . host , endpoint . port , resolved ) ;
89
+ eventEmitter ( 'sentinelError' , new Error ( 'connected to sentinel ' + endpoint . host + ':' + endpoint . port + ' successfully, but got a invalid reply: ' + resolved ) ) ;
84
90
connectToNext ( ) ;
85
91
}
86
92
} ) ;
0 commit comments