diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index 9520dcdb2..d800f21a6 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -7,7 +7,7 @@ Current package versions: | [![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) | ## Unreleased -- 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)) +- 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) - Changes max default retry policy backoff to 60 seconds ([#2853 by NickCraver](https://github.com/StackExchange/StackExchange.Redis/pull/2853)) - 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)) diff --git a/src/StackExchange.Redis/PhysicalBridge.cs b/src/StackExchange.Redis/PhysicalBridge.cs index 56dd0f5c5..b1736ccb2 100644 --- a/src/StackExchange.Redis/PhysicalBridge.cs +++ b/src/StackExchange.Redis/PhysicalBridge.cs @@ -550,6 +550,12 @@ internal void OnFullyEstablished(PhysicalConnection connection, string source) private int connectStartTicks; private long connectTimeoutRetryCount = 0; + private bool DueForConnectRetry() + { + int connectTimeMilliseconds = unchecked(Environment.TickCount - Thread.VolatileRead(ref connectStartTicks)); + return Multiplexer.RawConfig.ReconnectRetryPolicy.ShouldRetry(Interlocked.Read(ref connectTimeoutRetryCount), connectTimeMilliseconds); + } + internal void OnHeartbeat(bool ifConnectedOnly) { bool runThisTime = false; @@ -575,9 +581,7 @@ internal void OnHeartbeat(bool ifConnectedOnly) switch (state) { case (int)State.Connecting: - int connectTimeMilliseconds = unchecked(Environment.TickCount - Thread.VolatileRead(ref connectStartTicks)); - bool shouldRetry = Multiplexer.RawConfig.ReconnectRetryPolicy.ShouldRetry(Interlocked.Read(ref connectTimeoutRetryCount), connectTimeMilliseconds); - if (shouldRetry) + if (DueForConnectRetry()) { Interlocked.Increment(ref connectTimeoutRetryCount); var ex = ExceptionFactory.UnableToConnect(Multiplexer, "ConnectTimeout"); @@ -679,7 +683,7 @@ internal void OnHeartbeat(bool ifConnectedOnly) shouldResetConnectionRetryCount = false; Interlocked.Exchange(ref connectTimeoutRetryCount, 0); } - if (!ifConnectedOnly) + if (!ifConnectedOnly && DueForConnectRetry()) { Multiplexer.Trace("Resurrecting " + ToString()); Multiplexer.OnResurrecting(ServerEndPoint.EndPoint, ConnectionType); diff --git a/tests/StackExchange.Redis.Tests/ConnectingFailDetectionTests.cs b/tests/StackExchange.Redis.Tests/ConnectingFailDetectionTests.cs index db8d1dd1a..bc0fa9d0c 100644 --- a/tests/StackExchange.Redis.Tests/ConnectingFailDetectionTests.cs +++ b/tests/StackExchange.Redis.Tests/ConnectingFailDetectionTests.cs @@ -18,6 +18,7 @@ public async Task FastNoticesFailOnConnectingSyncCompletion() try { using var conn = Create(keepAlive: 1, connectTimeout: 10000, allowAdmin: true, shared: false); + conn.RawConfig.ReconnectRetryPolicy = new LinearRetry(200); var db = conn.GetDatabase(); db.Ping(); @@ -57,6 +58,7 @@ public async Task FastNoticesFailOnConnectingAsyncCompletion() try { using var conn = Create(keepAlive: 1, connectTimeout: 10000, allowAdmin: true, shared: false); + conn.RawConfig.ReconnectRetryPolicy = new LinearRetry(200); var db = conn.GetDatabase(); db.Ping();