Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Cli/dotnet/Installer/Windows/TimestampedFileLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,18 @@ protected override void WriteMessage(string message)
{
if (!_messageQueue.IsAddingCompleted)
{
_messageQueue.Add(message);
try
{
_messageQueue.Add(message);
Comment on lines 177 to +181
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

IsAddingCompleted check is still a TOCTOU gate (state can change immediately after the check). Since Add is now wrapped to handle disposal/completion races, consider removing the IsAddingCompleted check (or including it inside the try/catch) and just attempt the Add, dropping messages on InvalidOperationException/ObjectDisposedException. This reduces duplicated branching and eliminates an extra race window.

Copilot uses AI. Check for mistakes.
}
catch (ObjectDisposedException)
{
// The logger was disposed between the IsAddingCompleted check and Add.
}
catch (InvalidOperationException)
{
// CompleteAdding was called between the IsAddingCompleted check and Add.
}
Comment on lines +179 to +190
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

This change is intended to prevent unhandled exceptions when Dispose() races with background logging threads. Please add a regression test that disposes the TimestampedFileLogger while one or more threads are concurrently calling LogMessage/WriteMessage, and asserts the operation completes without throwing (and optionally that logging stops cleanly).

Copilot uses AI. Check for mistakes.
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7092,4 +7092,4 @@
}
}
]
}
}
Loading