Skip to content

Fix unhandled ObjectDisposedException in TimestampedFileLogger during workload repair - #54097

Merged
nagilson merged 1 commit into
mainfrom
copilot/fix-unhandled-exception-wasm-tools-repair
Jun 8, 2026
Merged

nagilson merged 1 commit into
mainfrom
copilot/fix-unhandled-exception-wasm-tools-repair

Conversation

Copilot AI commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

After dotnet workload repair completes on Windows, an unhandled ObjectDisposedException crashes the process because BlockingCollection<T>.IsAddingCompleted itself throws when the collection is already disposed — and that check sat outside the try-catch in WriteMessage.

The race: Shutdown() disposes the logger, then the elevated server process exit fires Process.Exited asynchronously on a threadpool thread (InstallClientElevationContext.ServerExited → LogMessage → WriteMessage), hitting the disposed BlockingCollection.

Change

  • TimestampedFileLogger.WriteMessage: expand the try-catch to also cover the IsAddingCompleted property access, not just Add().
// Before — IsAddingCompleted outside try, throws ObjectDisposedException unhandled
if (!_messageQueue.IsAddingCompleted)
{
    try { _messageQueue.Add(message); }
    catch (ObjectDisposedException) { }
    catch (InvalidOperationException) { }
}

// After — entire guard + add is protected
try
{
    if (!_messageQueue.IsAddingCompleted)
        _messageQueue.Add(message);
}
catch (ObjectDisposedException) { }
catch (InvalidOperationException) { }

Copilot AI changed the title [WIP] Fix unhandled exception during android wasm-tools repair Fix unhandled ObjectDisposedException in TimestampedFileLogger during workload repair Apr 27, 2026
Copilot AI requested a review from marcpopMSFT April 27, 2026 16:08
@marcpopMSFT
marcpopMSFT marked this pull request as ready for review May 1, 2026 22:27
Copilot AI review requested due to automatic review settings May 1, 2026 22:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a shutdown race in the Windows workload repair logging path where TimestampedFileLogger.WriteMessage could throw an unhandled ObjectDisposedException after the logger was disposed.

Changes:

  • Wrapes the BlockingCollection.IsAddingCompleted check in the existing exception handling so disposal races no longer crash the process.

@marcpopMSFT
marcpopMSFT force-pushed the copilot/fix-unhandled-exception-wasm-tools-repair branch 2 times, most recently from d448959 to 0ec020b Compare May 11, 2026 23:38
@marcpopMSFT
marcpopMSFT force-pushed the copilot/fix-unhandled-exception-wasm-tools-repair branch from 0ec020b to b7570b2 Compare May 12, 2026 23:57
@marcpopMSFT
marcpopMSFT requested a review from nagilson May 12, 2026 23:57
@nagilson
nagilson merged commit 0433ad2 into main Jun 8, 2026
24 checks passed
@nagilson
nagilson deleted the copilot/fix-unhandled-exception-wasm-tools-repair branch June 8, 2026 21:06
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants