Repository navigation
test(msbuild): serialize process-wide env mutation across MsBuild fixtures - #5062
Merged
arturcic merged 1 commit intoJul 14, 2026
Conversation
asbjornu
reviewed
Jul 14, 2026
arturcic
force-pushed
the
feature/managed-git-msbuild-env-race
branch
from
July 14, 2026 09:12
2fc613b to
537fe76
Compare
…tures The MsBuild task fixtures manipulate real process-wide environment variables so the task can detect the current build agent, and the MsBuild.exe fixture launches a child process that inherits that environment. Under [assembly: Parallelizable(ParallelScope.Fixtures)] these fixtures run concurrently, so one fixture setting/resetting a CI variable such as TF_BUILD races with another's task execution or child process launch: - an Azure task could see TF_BUILD cleared by a concurrent fixture and fall back to LocalBuild, emitting no ##vso output (empty log); and - a non-CI MSBuild child could inherit TF_BUILD=true left set by a concurrent Azure task and wrongly emit ##vso output. This surfaced as intermittent WriteVersionInfoTest failures that were far more frequent under the managed git backend, whose CLI-driven normalization makes each task execution much slower and therefore widens the racing window; the git backend itself computes the correct version in every case. Introduce a shared MsBuildProcessEnvironment lock/reset helper and hold it around the whole set-env/execute/reset window in both fixtures, launching the MSBuild child from a clean, reset environment. This makes the environment-sensitive sections mutually exclusive without disabling fixture parallelism. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
arturcic
force-pushed
the
feature/managed-git-msbuild-env-race
branch
from
July 14, 2026 09:23
537fe76 to
20ed7ea
Compare
|
Contributor
|
Thank you @arturcic for your contribution! |
arturcic
added a commit
that referenced
this pull request
Jul 16, 2026
…v-race test(msbuild): serialize process-wide env mutation across MsBuild fixtures
arturcic
added a commit
that referenced
this pull request
Jul 16, 2026
…v-race test(msbuild): serialize process-wide env mutation across MsBuild fixtures
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
Fixes an intermittent
WriteVersionInfoTasktest failure that showed up far more often under the managed Git backend. Investigation (dual-backend) traced it to a pre-existing process-global environment-variable race in the MsBuild test fixtures, not the git backend.Part of #5031.
Root cause
MsBuildTaskFixturemutates the real process environment (set/resetTF_BUILDetc.) so the task can detect the build agent, andMsBuildExeFixturelaunches a child process that inherits it. Under[assembly: Parallelizable(ParallelScope.Fixtures)]these race:TF_BUILDcleared by a concurrent fixture → falls back toLocalBuild, emits no##vsooutput (empty log); orTF_BUILD=trueleft set by a concurrent Azure fixture → wrongly emits##vso.The git backend computes the correct version in every case — the managed backend only widened the race window (~14×) because its CLI-driven normalization makes each task execution much slower (~2.8s vs libgit2 ~0.2s). The race is latent on libgit2 too.
Fix (test-infra only; product code untouched)
New
MsBuildProcessEnvironmenthelper with a shared lock +Reset()/Apply(). Both fixtures hold the lock across the whole reset→set→execute→reset window (and the exe fixture resets before launching the child), making the environment-sensitive sections mutually exclusive without disabling fixture parallelism.Verification
GitVersion.Git.Managed.Tests141/141;src+new-clibuild 0/0;dotnet format --verify-no-changesclean. No product or libgit2 code changed.🤖 Generated with Claude Code