[vs18.5] Fix race condition in LoggingService.ProcessLoggingEvent after shutdown#13549
Merged
[vs18.5] Fix race condition in LoggingService.ProcessLoggingEvent after shutdown#13549
Conversation
ProcessLoggingEvent accessed _eventQueue, _dequeueEvent, and _enqueueEvent directly without checking if the service had been shut down. When an external callback (e.g., Process.Exited from a ProjectCachePlugin) attempted to log after ShutdownComponent() had nullified these fields, a NullReferenceException (access violation 0xC0000005) would occur. The fix: 1. Early return when _serviceState == LoggingServiceState.Shutdown, matching the guard pattern already used by RegisterLogger, RegisterDistributedLogger, InitializeNodeLoggers, and InitializeComponent. 2. Capture field references to local variables before use, matching the existing pattern in LoggingEventProc (the queue pump thread). 3. Null-check the captured locals as a second defense against the race between the _serviceState check and field reads during concurrent shutdown.
…tion, Shouldly consistency - Wrap wait-handle operations (WaitOne/Set) in try/catch for ObjectDisposedException, since shutdown can dispose handles after they are captured into locals but before they are used. - Assert logThread.Join result to prevent silent test hangs. - Switch Assert.Equal to Shouldly ShouldBe for consistency with the rest of the test file.
SimaTian
approved these changes
Apr 17, 2026
GangWang01
approved these changes
Apr 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #13450 to vs18.5
/cc @rainersigwald @YuliiaKovalova