From ee80c29fb30eb12756c168c210f5722ec0d3a038 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Thu, 1 Jan 2026 16:17:48 +0000 Subject: [PATCH] fix: Handle ObjectDisposedException when disposing linked CancellationTokenSource MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../Engine/Executors/PrintProgressExecutor.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ModularPipelines/Engine/Executors/PrintProgressExecutor.cs b/src/ModularPipelines/Engine/Executors/PrintProgressExecutor.cs index 520d06bf84..5d677d8512 100644 --- a/src/ModularPipelines/Engine/Executors/PrintProgressExecutor.cs +++ b/src/ModularPipelines/Engine/Executors/PrintProgressExecutor.cs @@ -46,7 +46,14 @@ public async Task InitializeAsync() public async ValueTask DisposeAsync() { - _printProgressCancellationTokenSource?.CancelAfter(ProgressPrinterGracePeriodMs); + try + { + _printProgressCancellationTokenSource?.CancelAfter(ProgressPrinterGracePeriodMs); + } + catch (ObjectDisposedException) + { + // Linked CancellationTokenSource may already be disposed if the engine token was cancelled + } await SafelyAwaitProgressPrinter().ConfigureAwait(false);