Skip to content

Commit 3bd3e66

Browse files
authored
Track client-initiated shutdown for any pipe type. Fixes #2652 (#2814)
1 parent fe04b9a commit 3bd3e66

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/StackExchange.Redis/PhysicalConnection.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ private static readonly Message
5555

5656
private int failureReported;
5757

58+
private int clientSentQuit;
59+
5860
private int lastWriteTickCount, lastReadTickCount, lastBeatTickCount;
5961

6062
private long bytesLastResult;
@@ -375,15 +377,6 @@ internal void SimulateConnectionFailure(SimulatedFailureType failureType)
375377
}
376378
}
377379

378-
/// <summary>
379-
/// Did we ask for the shutdown? If so this leads to informational messages for tracking but not errors.
380-
/// </summary>
381-
private bool IsRequestedShutdown(PipeShutdownKind kind) => kind switch
382-
{
383-
PipeShutdownKind.ProtocolExitClient => true,
384-
_ => false,
385-
};
386-
387380
public void RecordConnectionFailed(
388381
ConnectionFailureType failureType,
389382
Exception? innerException = null,
@@ -436,12 +429,12 @@ public void RecordConnectionFailed(
436429

437430
var exMessage = new StringBuilder(failureType.ToString());
438431

432+
// If the reason for the shutdown was we asked for the socket to die, don't log it as an error (only informational)
433+
weAskedForThis = Thread.VolatileRead(ref clientSentQuit) != 0;
434+
439435
var pipe = connectingPipe ?? _ioPipe;
440436
if (pipe is SocketConnection sc)
441437
{
442-
// If the reason for the shutdown was we asked for the socket to die, don't log it as an error (only informational)
443-
weAskedForThis = IsRequestedShutdown(sc.ShutdownKind);
444-
445438
exMessage.Append(" (").Append(sc.ShutdownKind);
446439
if (sc.SocketError != SocketError.Success)
447440
{
@@ -904,8 +897,12 @@ internal void WriteHeader(RedisCommand command, int arguments, CommandBytes comm
904897

905898
internal void WriteRaw(ReadOnlySpan<byte> bytes) => _ioPipe?.Output?.Write(bytes);
906899

907-
internal void RecordQuit() // don't blame redis if we fired the first shot
908-
=> (_ioPipe as SocketConnection)?.TrySetProtocolShutdown(PipeShutdownKind.ProtocolExitClient);
900+
internal void RecordQuit()
901+
{
902+
// don't blame redis if we fired the first shot
903+
Thread.VolatileWrite(ref clientSentQuit, 1);
904+
(_ioPipe as SocketConnection)?.TrySetProtocolShutdown(PipeShutdownKind.ProtocolExitClient);
905+
}
909906

910907
internal static void WriteMultiBulkHeader(PipeWriter output, long count)
911908
{

0 commit comments

Comments
 (0)