Skip to content

Fix HTML logger parallel file collision with atomic file creation#15562

Merged
nohwnd merged 1 commit intomicrosoft:mainfrom
nohwnd:fix-html-logger
Mar 24, 2026
Merged

Fix HTML logger parallel file collision with atomic file creation#15562
nohwnd merged 1 commit intomicrosoft:mainfrom
nohwnd:fix-html-logger

Conversation

@nohwnd
Copy link
Copy Markdown
Member

@nohwnd nohwnd commented Mar 24, 2026

Summary

Fix cross-process race condition in HTML logger file creation that causes collisions when multiple test processes run in parallel.

This is a cleaned-up version of #15435.

Changes

  • Atomic file creation: Replace lock + File.Exists check with FileMode.CreateNew in GenerateUniqueFilePath. The lock only protected within a single process; FileMode.CreateNew is atomic at the OS level across all processes.
  • Fractional-second timestamps: Add fractional seconds (\ ffffff) to the timestamp format in both \FormatDateTimeForRunName\ and the \LogFilePrefix\ path, providing better uniqueness when multiple processes start near-simultaneously.
  • Remove dead code: Remove the now-unnecessary static \FileCreateLockObject.
  • Add test: Verify the generated filename contains the fractional-seconds timestamp pattern.

Closes #15404

Copilot AI review requested due to automatic review settings March 24, 2026 07:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes cross-process collisions in the HTML logger’s output file creation by switching to OS-level atomic file creation and increasing timestamp granularity.

Changes:

  • Use FileMode.CreateNew in GenerateUniqueFilePath to avoid cross-process races.
  • Add fractional-second timestamps (fffffff) to output naming for better uniqueness.
  • Add a unit test asserting the fractional-second filename pattern.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
test/Microsoft.TestPlatform.Extensions.HtmlLogger.UnitTests/HtmlLoggerTests.cs Adds coverage for the new fractional-second timestamp filename format.
src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs Implements atomic file creation and updates timestamp formats used in generated filenames.

Copilot AI review requested due to automatic review settings March 24, 2026 07:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Replace lock-based file creation with atomic FileMode.CreateNew to prevent
cross-process race conditions when multiple test processes generate HTML
log files simultaneously.

Changes:
- Use FileMode.CreateNew instead of lock + File.Exists check in
  GenerateUniqueFilePath, making file creation atomic across processes
- Add fractional seconds (fffffff) to timestamp format for better
  cross-process uniqueness in both FormatDateTimeForRunName and the
  LogFilePrefix path
- Remove static FileCreateLockObject that only protected within a
  single process
- Add test verifying fractional-seconds timestamp in generated filenames

Fixes microsoft#15404

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nohwnd nohwnd added the 🚢 Ship it! Add to PRs where owner approves automated PR, but cannot approve because they "wrote it". label Mar 24, 2026
@nohwnd nohwnd merged commit a18c01f into microsoft:main Mar 24, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🚢 Ship it! Add to PRs where owner approves automated PR, but cannot approve because they "wrote it".

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTML logger sometimes shows error when using multiple vstest runner in parallel

3 participants