From eab77cd49af719bb41fd2408ae69f3dd8509af5d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 05:50:29 +0000 Subject: [PATCH 1/3] Initial plan From c5ba9ec7de53d118c01666d524febff175193a74 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 05:52:28 +0000 Subject: [PATCH 2/3] fix: treat receive-loop shutdown cancellations as expected flow Agent-Logs-Url: https://github.com/slaveOftime/wechat-relay/sessions/f8bbb120-ea7a-4857-97b0-8e7cf20bce88 Co-authored-by: albertwoo <8017681+albertwoo@users.noreply.github.com> --- WeChatRelay/Services/WeChatService.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/WeChatRelay/Services/WeChatService.cs b/WeChatRelay/Services/WeChatService.cs index 2b4bfd0..1d9c6c5 100644 --- a/WeChatRelay/Services/WeChatService.cs +++ b/WeChatRelay/Services/WeChatService.cs @@ -259,7 +259,7 @@ public async Task StartReceivingAsync(Func onMessage, Canc } } } - catch (OperationCanceledException) when (ct.IsCancellationRequested) { break; } + catch (Exception ex) when (IsExpectedReceiveLoopCancellation(ex, ct)) { break; } catch (Exception ex) { log.LogError(ex, "Receive loop error"); @@ -268,6 +268,20 @@ public async Task StartReceivingAsync(Func onMessage, Canc } } + private static bool IsExpectedReceiveLoopCancellation(Exception ex, CancellationToken ct) + { + if (!ct.IsCancellationRequested) + return false; + + for (var current = ex; current is not null; current = current.InnerException) + { + if (current is OperationCanceledException or ObjectDisposedException) + return true; + } + + return false; + } + public List GetSendToCandidates() { var candidates = new List(); From 703cd90cdd36182f5cf7725bef615c97790a5882 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 05:59:20 +0000 Subject: [PATCH 3/3] refactor: simplify receive loop cancellation catches Agent-Logs-Url: https://github.com/slaveOftime/wechat-relay/sessions/806538f9-ec7d-4e32-8a76-5e7026392124 Co-authored-by: albertwoo <8017681+albertwoo@users.noreply.github.com> --- WeChatRelay/Services/WeChatService.cs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/WeChatRelay/Services/WeChatService.cs b/WeChatRelay/Services/WeChatService.cs index 1d9c6c5..f303bca 100644 --- a/WeChatRelay/Services/WeChatService.cs +++ b/WeChatRelay/Services/WeChatService.cs @@ -259,7 +259,8 @@ public async Task StartReceivingAsync(Func onMessage, Canc } } } - catch (Exception ex) when (IsExpectedReceiveLoopCancellation(ex, ct)) { break; } + catch (TaskCanceledException) when (ct.IsCancellationRequested) { break; } + catch (OperationCanceledException) when (ct.IsCancellationRequested) { break; } catch (Exception ex) { log.LogError(ex, "Receive loop error"); @@ -268,20 +269,6 @@ public async Task StartReceivingAsync(Func onMessage, Canc } } - private static bool IsExpectedReceiveLoopCancellation(Exception ex, CancellationToken ct) - { - if (!ct.IsCancellationRequested) - return false; - - for (var current = ex; current is not null; current = current.InnerException) - { - if (current is OperationCanceledException or ObjectDisposedException) - return true; - } - - return false; - } - public List GetSendToCandidates() { var candidates = new List();