#6570·winget-cli

FileLogger is not thread-safe; concurrent writes can produce torn log lines

Author: nilspepCreated Sep 26, 2026Updated Sep 26, 2026
LabelsNeeds-TriageCommand-Configure

Relevant area(s)

WinGet CLI

Relevant command(s)

winget configure

Brief description of your issue

AppInstaller::Logging::FileLogger writes to one std::ofstream without any synchronization. When the same diagnostic logger is used from several threads, records can interleave inside a line, and the maximum-size wrap can race with other writes. The result is torn or merged lines in the WinGet log.

Upstream code already logs to the same context logger from other threads. For example, winget configure routes configuration processor diagnostics (processor.Diagnostics(...) in ConfigurationFlow.cpp) and WinRT progress callbacks into the context's diagnostic logger.

Proposed fix: a per-instance mutex in FileLogger that serializes WriteDirect (which Write uses), SetTag(HeadersComplete) and SetMaximumSize. I have a small PR with a regression test ready.

Steps to reproduce

Unit-level repro: 8 threads each write 1,000 records through one FileLogger, using both Write and WriteDirect, with and without a maximum file size. Then check that every line in the file is exactly one complete record.

Expected behavior

Each log record is written as one complete line.

Actual behavior

On an x64 Release build, the check failed in 3 of 3 runs: some lines contained parts of several records.

Environment

Windows 11 Enterprise 26200, x64 Release build of master at 9f3476831b8026797ca454841b96202a2c99a07b.