Skip to content

BuildFailureLogInvariant races with intentional exception dump across test assemblies #14740

Closed

Description

@JeremyKuhne

Issue Description

BuildFailureLogInvariant can race with DebugUtils_Tests.DumpExceptionToFileShouldWriteInDebugDumpPath when test assemblies run concurrently. The invariant can discover and delete the exception dump intentionally created by the other test process, causing both assemblies to fail.

This occurred on the macOS Core leg of build 20260818.45.

Steps to Reproduce

The race is timing-dependent. Run the Framework and Engine test assemblies concurrently, as the PR pipeline does through:

./build.sh --ci --test --stage2Argument '/mt'

The immediately preceding PR build passed, while build 1558372 hit the collision.

Expected Behavior

The Engine test should create, verify, and delete its intentional exception dump without affecting invariants in other test processes. Framework tests should not observe files owned by another concurrently running test assembly.

Actual Behavior

The Framework test assembly reported a method-cleanup error from BuildFailureLogInvariant:

Assert.Equal() Failure: Values differ
Expected: 1
Actual:   2

Azure expanded that single cleanup error into 14 failed FileMatcherTest.NormalizeTest theory rows. The Engine assembly simultaneously failed DebugUtils_Tests.DumpExceptionToFileShouldWriteInDebugDumpPath with:

System.IO.FileNotFoundException: Could not find file
'/Users/runner/work/1/s/artifacts/log/Debug/MsbuildDebugLogs/MSBuild_pid-67562_94521bf761fe499aa3b5dc9d7b00a639.failure.txt'.

Analysis

The custom test runner wraps every test in TestEnvironment.Create(), which installs BuildFailureLogInvariant. That invariant snapshots shared MSBuild_*.txt locations, then reads and deletes newly discovered files during cleanup.

DumpExceptionToFileShouldWriteInDebugDumpPath intentionally writes an MSBuild_*failure.txt file to the shared debug directory and expects to read and delete it itself. Test assemblies execute in separate processes concurrently, but they share that directory.

The captured timestamps show the collision boundary:

  • The final NormalizeTest case finished at 01:06:55.4555760Z.
  • DumpExceptionToFileShouldWriteInDebugDumpPath started at 01:06:55.4620100Z.
  • The Framework invariant ran after xUnit recorded the test finish, observed the Engine process's new file, and deleted it before the Engine test read it.

A durable fix is to route the intentional dump test to a test-owned directory:

  1. Create a unique folder with TestEnvironment.
  2. Set MSBUILDDEBUGPATH to that folder and call FrameworkDebugUtils.SetDebugPath().
  3. Refresh DebugUtils.DebugDumpPath before the test.
  4. Restore both debug-path layers in finally.

The invariant should not broadly ignore MSBuild_*failure.txt, because those files normally indicate real MSBuild crashes.

Relevant code:

Versions & Configurations

  • macOS x64 PR leg
  • .NET SDK 11.0.100-preview.7.26360.111
  • Stage 2 build with /mt
  • Azure DevOps build 1558372

Activity

  1. added
    Area: Our Own Build
    flaky-test
    on Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area: Our Own BuildArea: Testsflaky-test

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions