Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/StackExchange.Redis/PhysicalBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Loading