From c1e7cd607418c6d2d16fb686bd4333701cf03f1c Mon Sep 17 00:00:00 2001 From: Sergey Anisimov Date: Fri, 5 Sep 2025 12:29:33 +0200 Subject: [PATCH] Guard PipeReader.AdvanceTo on closed socket Problem: A race during shutdown could call reader.AdvanceTo(buffer.Start, buffer.End) after the TCP socket is closed, risking exceptions that propagate via reader.CompleteAsync(caught) and noisy logs. Change: In Connection.ProcessIncomingFrames, only call reader.AdvanceTo(...) when socket.Connected is true. --- RabbitMQ.Stream.Client/Connection.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/RabbitMQ.Stream.Client/Connection.cs b/RabbitMQ.Stream.Client/Connection.cs index a1a5cb06..72f9c133 100644 --- a/RabbitMQ.Stream.Client/Connection.cs +++ b/RabbitMQ.Stream.Client/Connection.cs @@ -189,7 +189,10 @@ private async Task ProcessIncomingFrames() numFrames += 1; } - reader.AdvanceTo(buffer.Start, buffer.End); + if (socket.Connected) + { + reader.AdvanceTo(buffer.Start, buffer.End); + } } } catch (OperationCanceledException e)