From 74eb8beb8998b11c814de87f894230956713b96b Mon Sep 17 00:00:00 2001 From: Blank Date: Wed, 5 Aug 2026 16:48:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(connection):=20=E5=85=B3=E9=97=AD=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E6=97=B6=E5=8F=96=E6=B6=88=E8=BE=93=E5=87=BA=E7=AE=A1?= =?UTF-8?q?=E9=81=93=E7=9A=84=E6=8C=82=E8=B5=B7=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 补齐 c8308040 缺失的 CancelOutputPendingRead 机制:CancelAsync 完成输出 writer 后调用 Output.Reader.CancelPendingRead(),并新增 PipeConnection 的 override,强制解除 ProcessSends 在 ReadAsync(CancellationToken.None) 上的阻塞,使发送循环在连接关闭时确定性地退出。 Linear: GFX-309 --- src/GameFrameX.SuperSocket.Connection/PipeConnection.cs | 8 ++++++++ .../PipeConnectionBase.cs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/GameFrameX.SuperSocket.Connection/PipeConnection.cs b/src/GameFrameX.SuperSocket.Connection/PipeConnection.cs index 7889bc930..7184c47b3 100644 --- a/src/GameFrameX.SuperSocket.Connection/PipeConnection.cs +++ b/src/GameFrameX.SuperSocket.Connection/PipeConnection.cs @@ -262,5 +262,13 @@ protected override bool IsIgnorableException(Exception e) /// A token to monitor for cancellation requests. /// The total number of bytes read. protected abstract ValueTask FillInputPipeWithDataAsync(Memory memory, CancellationToken cancellationToken); + + /// + /// Cancels the pending read on the output pipe reader so the send loop unblocks immediately when the connection is being closed. + /// + protected override void CancelOutputPendingRead() + { + this.Output.Reader.CancelPendingRead(); + } } } diff --git a/src/GameFrameX.SuperSocket.Connection/PipeConnectionBase.cs b/src/GameFrameX.SuperSocket.Connection/PipeConnectionBase.cs index cab023029..29b585a8d 100644 --- a/src/GameFrameX.SuperSocket.Connection/PipeConnectionBase.cs +++ b/src/GameFrameX.SuperSocket.Connection/PipeConnectionBase.cs @@ -192,6 +192,7 @@ protected async Task CancelAsync() _cts.Cancel(); await CompleteWriterAsync(OutputWriter, _isDetaching).ConfigureAwait(false); + CancelOutputPendingRead(); } /// @@ -579,6 +580,13 @@ protected virtual async ValueTask CompleteWriterAsync(PipeWriter writer, bool is await writer.CompleteAsync().ConfigureAwait(false); } + /// + /// Cancels the pending read on the output pipe reader so that the send loop () blocked on ReadAsync returns promptly during connection shutdown. + /// + protected virtual void CancelOutputPendingRead() + { + } + internal struct BufferFilterResult { public Exception Exception { get; set; }