Skip to content

Commit b78a2ea

Browse files
thomhurstclaude
andauthored
fix: Handle ObjectDisposedException when disposing linked CancellationTokenSource (#1714)
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>
1 parent 7412b8d commit b78a2ea

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/ModularPipelines/Engine/Executors/PrintProgressExecutor.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ public async Task<IPrintProgressExecutor> InitializeAsync()
4646

4747
public async ValueTask DisposeAsync()
4848
{
49-
_printProgressCancellationTokenSource?.CancelAfter(ProgressPrinterGracePeriodMs);
49+
try
50+
{
51+
_printProgressCancellationTokenSource?.CancelAfter(ProgressPrinterGracePeriodMs);
52+
}
53+
catch (ObjectDisposedException)
54+
{
55+
// Linked CancellationTokenSource may already be disposed if the engine token was cancelled
56+
}
5057

5158
await SafelyAwaitProgressPrinter().ConfigureAwait(false);
5259

0 commit comments

Comments
 (0)