Skip to content

Commit 50f2218

Browse files
authored
Fix: Rexpect backoff in the disconnect -> resurrection case as well (#2856)
Additional case handling for #2853, respecting backoff in the disconnected -> resurrecting state case. We need to check backoff in that flow as well to prevent a premature `TryConnect`.
1 parent 2a47eb5 commit 50f2218

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

docs/ReleaseNotes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Current package versions:
77
| [![StackExchange.Redis](https://img.shields.io/nuget/v/StackExchange.Redis.svg)](https://www.nuget.org/packages/StackExchange.Redis/) | [![StackExchange.Redis](https://img.shields.io/nuget/vpre/StackExchange.Redis.svg)](https://www.nuget.org/packages/StackExchange.Redis/) | [![StackExchange.Redis MyGet](https://img.shields.io/myget/stackoverflow/vpre/StackExchange.Redis.svg)](https://www.myget.org/feed/stackoverflow/package/nuget/StackExchange.Redis) |
88

99
## Unreleased
10-
- Fix: Respect `IReconnectRetryPolicy` timing in the case that a node that was present disconnects indefinitely ([#2853 by NickCraver](https://github.com/StackExchange/StackExchange.Redis/pull/2853))
10+
- Fix: Respect `IReconnectRetryPolicy` timing in the case that a node that was present disconnects indefinitely ([#2853](https://github.com/StackExchange/StackExchange.Redis/pull/2853) & [#2856](https://github.com/StackExchange/StackExchange.Redis/pull/2856) by NickCraver)
1111
- Changes max default retry policy backoff to 60 seconds ([#2853 by NickCraver](https://github.com/StackExchange/StackExchange.Redis/pull/2853))
1212
- Fix [#2652](https://github.com/StackExchange/StackExchange.Redis/issues/2652): Track client-initiated shutdown for any pipe type ([#2814 by bgrainger](https://github.com/StackExchange/StackExchange.Redis/pull/2814))
1313

src/StackExchange.Redis/PhysicalBridge.cs

+8-4
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);

tests/StackExchange.Redis.Tests/ConnectingFailDetectionTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public async Task FastNoticesFailOnConnectingSyncCompletion()
1818
try
1919
{
2020
using var conn = Create(keepAlive: 1, connectTimeout: 10000, allowAdmin: true, shared: false);
21+
conn.RawConfig.ReconnectRetryPolicy = new LinearRetry(200);
2122

2223
var db = conn.GetDatabase();
2324
db.Ping();
@@ -57,6 +58,7 @@ public async Task FastNoticesFailOnConnectingAsyncCompletion()
5758
try
5859
{
5960
using var conn = Create(keepAlive: 1, connectTimeout: 10000, allowAdmin: true, shared: false);
61+
conn.RawConfig.ReconnectRetryPolicy = new LinearRetry(200);
6062

6163
var db = conn.GetDatabase();
6264
db.Ping();

0 commit comments

Comments
 (0)