@@ -550,6 +550,12 @@ internal void OnFullyEstablished(PhysicalConnection connection, string source)
550550 private int connectStartTicks ;
551551 private long connectTimeoutRetryCount = 0 ;
552552
553+ private bool DueForConnectRetry ( )
554+ {
555+ int connectTimeMilliseconds = unchecked ( Environment . TickCount - Thread . VolatileRead ( ref connectStartTicks ) ) ;
556+ return Multiplexer . RawConfig . ReconnectRetryPolicy . ShouldRetry ( Interlocked . Read ( ref connectTimeoutRetryCount ) , connectTimeMilliseconds ) ;
557+ }
558+
553559 internal void OnHeartbeat ( bool ifConnectedOnly )
554560 {
555561 bool runThisTime = false ;
@@ -575,9 +581,7 @@ internal void OnHeartbeat(bool ifConnectedOnly)
575581 switch ( state )
576582 {
577583 case ( int ) State . Connecting :
578- int connectTimeMilliseconds = unchecked ( Environment . TickCount - Thread . VolatileRead ( ref connectStartTicks ) ) ;
579- bool shouldRetry = Multiplexer . RawConfig . ReconnectRetryPolicy . ShouldRetry ( Interlocked . Read ( ref connectTimeoutRetryCount ) , connectTimeMilliseconds ) ;
580- if ( shouldRetry )
584+ if ( DueForConnectRetry ( ) )
581585 {
582586 Interlocked . Increment ( ref connectTimeoutRetryCount ) ;
583587 var ex = ExceptionFactory . UnableToConnect ( Multiplexer , "ConnectTimeout" ) ;
@@ -679,7 +683,7 @@ internal void OnHeartbeat(bool ifConnectedOnly)
679683 shouldResetConnectionRetryCount = false ;
680684 Interlocked . Exchange ( ref connectTimeoutRetryCount , 0 ) ;
681685 }
682- if ( ! ifConnectedOnly )
686+ if ( ! ifConnectedOnly && DueForConnectRetry ( ) )
683687 {
684688 Multiplexer . Trace ( "Resurrecting " + ToString ( ) ) ;
685689 Multiplexer . OnResurrecting ( ServerEndPoint . EndPoint , ConnectionType ) ;
0 commit comments