Skip to content

Commit 5c2fab6

Browse files
committed
Fix: Rexpect backoff in the disconnect -> resurrection case as well
1 parent 2a47eb5 commit 5c2fab6

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/StackExchange.Redis/PhysicalBridge.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)