Skip to content

fix: Prevent ObjectDisposedException during CancellationTokenSource disposal - #28

Merged
x64-dev merged 1 commit into
mainfrom
seer/fix/services-4c-cts-disposed-exception
Jul 28, 2026
Merged

fix: Prevent ObjectDisposedException during CancellationTokenSource disposal#28
x64-dev merged 1 commit into
mainfrom
seer/fix/services-4c-cts-disposed-exception

Conversation

@seer-by-sentry

Copy link
Copy Markdown
Contributor

This commit addresses issue SERVICES-4C, an ObjectDisposedException occurring when a CancellationTokenSource (CTS) is disposed concurrently with its CancelAfter timer firing.

The root cause was a race condition in GenOnlineService/Constants.cs within the finally block after m_SockInternal.SendAsync. A CancellationTokenSource was created with CancelAfter(500ms) and then immediately disposed. If SendAsync completed just as the 500ms timer was about to fire, the timer's callback execution could attempt to access the already-disposed CTS, leading to the exception.

The fix involves calling cts.CancelAfter(Timeout.InfiniteTimeSpan) before cts.Dispose(). This disarms the pending timer, ensuring that it cannot fire after the CTS has been disposed, thereby eliminating the race condition and preventing the ObjectDisposedException.

Fixes SERVICES-4C

@x64-dev
x64-dev merged commit 01294bb into main Jul 28, 2026
0 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant