Skip to content
Merged
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
15 changes: 13 additions & 2 deletions src/StackExchange.Redis/ConnectionMultiplexer.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@ internal void OnConnectionAttemptCompleted(
var handler = RawConfig.ConnectionAttemptCompletedHandler;
if (handler != null)
{
var sequenceNumber = Interlocked.Increment(ref _connectionAttemptSequence);
// the sequence and the timestamp are taken together, so that they agree on the order: taken apart, two
// attempts completing at once (the interactive and subscription connections failing together) could each
// take one first and the other second, and a later sequence number would carry an earlier time
long sequenceNumber;
DateTime completedTimeUtc;
lock (_connectionAttemptSequenceLock)
{
sequenceNumber = ++_connectionAttemptSequence;
completedTimeUtc = DateTime.UtcNow;
}

CompleteAsWorker(new ConnectionAttemptCompletedEventArgs(
handler,
this,
Expand All @@ -39,12 +49,13 @@ internal void OnConnectionAttemptCompleted(
tlsHostName,
serverCertificateCheck,
sequenceNumber,
DateTime.UtcNow,
completedTimeUtc,
physicalName));
}
}

private long _connectionAttemptSequence;
private readonly object _connectionAttemptSequenceLock = new();

/// <summary>
/// Raised whenever a physical connection fails.
Expand Down
Loading