@@ -150,7 +150,10 @@ Cluster.prototype.connect = function () {
150
150
if ( this . options . enableReadyCheck ) {
151
151
this . _readyCheck ( function ( err , fail ) {
152
152
if ( err || fail ) {
153
- this . disconnect ( true ) ;
153
+ debug ( 'Ready check failed (%s). Reconnecting...' , err || fail )
154
+ if ( this . status === 'connect' ) {
155
+ this . disconnect ( true ) ;
156
+ }
154
157
} else {
155
158
readyHandler . call ( this ) ;
156
159
}
@@ -195,7 +198,9 @@ Cluster.prototype._handleCloseEvent = function () {
195
198
this . reconnectTimeout = setTimeout ( function ( ) {
196
199
this . reconnectTimeout = null ;
197
200
debug ( 'Cluster is disconnected. Retrying after %dms' , retryDelay ) ;
198
- this . connect ( ) . catch ( _ . noop ) ;
201
+ this . connect ( ) . catch ( function ( err ) {
202
+ debug ( 'Got error %s when reconnecting. Ignoring...' , err ) ;
203
+ } ) ;
199
204
} . bind ( this ) , retryDelay ) ;
200
205
} else {
201
206
this . setStatus ( 'end' ) ;
@@ -218,6 +223,7 @@ Cluster.prototype.disconnect = function (reconnect) {
218
223
if ( this . reconnectTimeout ) {
219
224
clearTimeout ( this . reconnectTimeout ) ;
220
225
this . reconnectTimeout = null ;
226
+ debug ( 'Canceled reconnecting attempts' ) ;
221
227
}
222
228
223
229
if ( status === 'wait' ) {
@@ -570,7 +576,7 @@ Cluster.prototype.handleError = function (error, ttl, handlers) {
570
576
timeout : this . options . retryDelayOnClusterDown ,
571
577
callback : this . refreshSlotsCache . bind ( this )
572
578
} ) ;
573
- } else if ( error . message === utils . CONNECTION_CLOSED_ERROR_MSG && this . options . retryDelayOnFailover > 0 ) {
579
+ } else if ( error . message === utils . CONNECTION_CLOSED_ERROR_MSG && this . options . retryDelayOnFailover > 0 && this . status === 'ready' ) {
574
580
this . delayQueue . push ( 'failover' , handlers . connectionClosed , {
575
581
timeout : this . options . retryDelayOnFailover ,
576
582
callback : this . refreshSlotsCache . bind ( this )
0 commit comments