fix: Handle ObjectDisposedException when disposing linked CancellationTokenSource#1714
Conversation
…nTokenSource When the engine cancellation token is cancelled, the linked CancellationTokenSource in PrintProgressExecutor may already be disposed by the time DisposeAsync is called. This causes an ObjectDisposedException when CancelAfter is called. Wrap the CancelAfter call in a try-catch to gracefully handle this race condition. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryFixes a race condition where Critical IssuesNone found ✅ SuggestionsThe fix looks good and follows existing patterns in the codebase (see One minor observation: The comment could be slightly more precise. Consider: // The linked CancellationTokenSource may already be disposed if the parent engine token was cancelledvs. the current: // Linked CancellationTokenSource may already be disposed if the engine token was cancelledBoth are fine - just a matter of consistency with the rest of the codebase. Verdict✅ APPROVE - No critical issues The fix correctly handles the race condition between the parent token cancellation (which disposes the linked token source) and the explicit disposal in |
There was a problem hiding this comment.
Pull request overview
This PR fixes a race condition in PrintProgressExecutor where calling CancelAfter on an already-disposed linked CancellationTokenSource throws ObjectDisposedException. The race occurs when the parent engine token is cancelled before DisposeAsync is invoked, causing the linked CTS to be disposed.
Key changes:
- Added try-catch block around
CancelAftercall to handleObjectDisposedException - Added explanatory comment describing when this race condition occurs
Summary
CancelAfteris called on an already-disposed linkedCancellationTokenSourceDisposeAsyncis calledCancelAftercall in a try-catch to gracefully handle this caseContext
This bug was exposed by the logging improvements in PR #1711. The error manifests as:
Test plan
🤖 Generated with Claude Code