Skip to content

Commit

Permalink
Track client-initiated shutdown for any pipe type. Fixes #2652
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrainger committed Nov 11, 2024
1 parent 0071148 commit 966111f
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/StackExchange.Redis/PhysicalConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ private static readonly Message

private int failureReported;

private int clientSentQuit;

private int lastWriteTickCount, lastReadTickCount, lastBeatTickCount;

private long bytesLastResult;
Expand Down Expand Up @@ -375,15 +377,6 @@ internal void SimulateConnectionFailure(SimulatedFailureType failureType)
}
}

/// <summary>
/// Did we ask for the shutdown? If so this leads to informational messages for tracking but not errors.
/// </summary>
private bool IsRequestedShutdown(PipeShutdownKind kind) => kind switch
{
PipeShutdownKind.ProtocolExitClient => true,
_ => false,
};

public void RecordConnectionFailed(
ConnectionFailureType failureType,
Exception? innerException = null,
Expand Down Expand Up @@ -436,12 +429,12 @@ public void RecordConnectionFailed(

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

// If the reason for the shutdown was we asked for the socket to die, don't log it as an error (only informational)
weAskedForThis = Thread.VolatileRead(ref clientSentQuit) != 0;

var pipe = connectingPipe ?? _ioPipe;
if (pipe is SocketConnection sc)
{
// If the reason for the shutdown was we asked for the socket to die, don't log it as an error (only informational)
weAskedForThis = IsRequestedShutdown(sc.ShutdownKind);

exMessage.Append(" (").Append(sc.ShutdownKind);
if (sc.SocketError != SocketError.Success)
{
Expand Down Expand Up @@ -904,8 +897,12 @@ internal void WriteHeader(RedisCommand command, int arguments, CommandBytes comm

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

internal void RecordQuit() // don't blame redis if we fired the first shot
=> (_ioPipe as SocketConnection)?.TrySetProtocolShutdown(PipeShutdownKind.ProtocolExitClient);
internal void RecordQuit()
{
// don't blame redis if we fired the first shot
Thread.VolatileWrite(ref clientSentQuit, 1);
(_ioPipe as SocketConnection)?.TrySetProtocolShutdown(PipeShutdownKind.ProtocolExitClient);
}

internal static void WriteMultiBulkHeader(PipeWriter output, long count)
{
Expand Down

0 comments on commit 966111f

Please sign in to comment.