Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
13 changes: 10 additions & 3 deletions src/StackExchange.Redis/ConnectionMultiplexer.Sentinel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,17 @@ public ConnectionMultiplexer GetSentinelMasterConnection(ConfigurationOptions co

// verify role is primary according to:
// https://redis.io/topics/sentinel-clients
if (connection.GetServer(newPrimaryEndPoint)?.Role()?.Value == RedisLiterals.master)
try
{
if (connection.GetServer(newPrimaryEndPoint)?.Role()?.Value == RedisLiterals.master)
{
success = true;
break;
}
}
catch (RedisTimeoutException)
{
success = true;
break;
// syncTimeout, could be transient
}

Thread.Sleep(100);
Expand Down
6 changes: 6 additions & 0 deletions src/StackExchange.Redis/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ bool ICompletable.TryComplete(bool isAsync)
return true;
}

private Random _rand = new();

public void Complete()
{
// Ensure we can never call Complete on the same resultBox from two threads by grabbing it now
Expand All @@ -446,6 +448,10 @@ public void Complete()
// set the completion/performance data
performance?.SetCompleted();

if (_rand.Next(0, 2) == 0 && Command == RedisCommand.ROLE)
{
Thread.Sleep(15);
}
currBox?.ActivateContinuations();
}

Expand Down
22 changes: 22 additions & 0 deletions tests/StackExchange.Redis.Tests/Issues/IssueXXXTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
using Xunit.Sdk;

namespace StackExchange.Redis.Tests.Issues;

public class IssueXXXTests(ITestOutputHelper output)
{
private readonly ITestOutputHelper _output = output;

[Fact]
public void Execute()
{
Parallel.For(0, 10, _ =>
{
using var conn = ConnectionMultiplexer.Connect(
$"abortConnect=false,syncTimeout=5,{TestConfig.Current.SentinelServer},serviceName={TestConfig.Current.SentinelSeviceName}");
});
}
}