Make FileLogger thread-safe - #6571
Open
Nils Peper (MSFT) (nilspep) wants to merge 1 commit into
Open
Nils Peper (MSFT) (nilspep) wants to merge 1 commit into
Nils Peper (MSFT) (nilspep) wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Author
|
@microsoft-github-policy-service agree company="Microsoft" |
FileLogger writes to a single std::ofstream without synchronization, so concurrent writers sharing a diagnostic logger can interleave records and race with the maximum-size wrap. Serialize WriteDirect, SetTag and SetMaximumSize with a per-instance mutex, held through a unique_ptr to keep FileLogger movable. Add a regression test with 8 concurrent writers that checks every line is one complete record.
Nils Peper (MSFT) (nilspep)
force-pushed
the
fix/filelogger-thread-safety
branch
from
September 28, 2026 07:07
743cf9a to
4163a2a
Compare
This comment was marked as off-topic.
This comment was marked as off-topic.
JohnMcPMS
approved these changes
Sep 29, 2026
Member
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
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.
📖 Description
FileLoggerwrites to a singlestd::ofstreamwithout synchronization. When a diagnostic logger is shared across threads, concurrentWrite/WriteDirectcalls can interleave inside one record, and the maximum-size wrap (HandleMaximumFileSize/WrapLogFile) can race with other writers. This can produce merged or torn log lines.Upstream code already writes to the same context logger from other threads. For example,
winget configureroutes configuration processor diagnostics (processor.Diagnostics(...)inConfigurationFlow.cpp) and WinRT progress callbacks into the context's diagnostic logger.This change adds a per-instance mutex that serializes:
WriteDirect, whichWriteuses; this covers the size check, wrapping and the stream write;SetTag(HeadersComplete);SetMaximumSize.The mutex is held through a
std::unique_ptrso thatFileLoggerstays movable. Single-threaded behavior and output format are unchanged.🔗 References
Resolves #6570
🔍 Validation
FileLogger_ConcurrentWritesPreserveCompleteLines: 8 threads write 1,000 records each, formatted and direct, with and without a maximum file size. Every line in the file must be exactly one complete record.AppInstallerCLITestssuite passes on x64 Release with the fix (1,123 test cases).✅ Checklist
🤖 AI Assistance
Fix designed by me; GitHub Copilot assisted with implementation, testing and validation under my direction.
📋 Issue Type
Microsoft Reviewers: Open in CodeFlow