From db14e3bd645ed42f5acefa24a20e8b1aa6bf60d2 Mon Sep 17 00:00:00 2001 From: x64-dev Date: Tue, 28 Jul 2026 20:33:14 +0000 Subject: [PATCH] fix: Prevent ObjectDisposedException during CancellationTokenSource disposal --- GenOnlineService/Constants.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/GenOnlineService/Constants.cs b/GenOnlineService/Constants.cs index 6c18add..03df735 100644 --- a/GenOnlineService/Constants.cs +++ b/GenOnlineService/Constants.cs @@ -1211,7 +1211,11 @@ public async Task SendAsync(byte[] buffer, WebSocketMessageType messageType, Can { try { - cts.Dispose(); + // Disarm the pending CancelAfter timer before disposing to prevent a race condition + // where the timer fires concurrently with Dispose(), causing ObjectDisposedException + // in CancellationTokenSource.ExecuteCallbackHandlers. + cts.CancelAfter(Timeout.InfiniteTimeSpan); + cts.Dispose(); } catch (ObjectDisposedException) {