You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MultiThreadedTaskEnvironmentDriver.GetProcessStartInfo() leaks inherited process env vars to child processes #13770
MultiThreadedTaskEnvironmentDriver.GetProcessStartInfo() (src/Framework/MultiThreadedTaskEnvironmentDriver.cs:112-126) does not
clear the inherited process environment before applying the virtualized _environmentVariables. The resulting ProcessStartInfo.EnvironmentVariables is lazily pre-populated with a snapshot of the MSBuild host process's env block, and the
loop only adds/overrides — never removes — entries.
As a result, any variable that was removed from the MT TaskEnvironment (via SetEnvironmentVariable(name, null) or SetEnvironment(...) replacing the dictionary) still leaks into spawned child processes if it existed in the host MSBuild process.
This breaks env-var isolation between concurrently building projects under multithreaded mode and prevents tasks from scrubbing
inherited variables before spawning children.
Expected
The child process's environment should be exactly what the MT TaskEnvironment exposes — nothing more, nothing less.
Actual
Child inherits MSBuild host env on top of the virtualized env.
Likely fix
Clear startInfo.Environment before copying _environmentVariables into it.
Acceptance criteria — tests to add
Add tests under src/Framework.UnitTests/ (or appropriate MT driver test location) reproducing the leak:
Removed variable does not leak
Set a process env var LEAK_TEST=yes (via TestEnvironment.SetEnvironmentVariable)
Construct a MultiThreadedTaskEnvironmentDriver (inherits host env)
Call SetEnvironmentVariable("LEAK_TEST", null)
Spawn cmd /c set LEAK_TEST (or sh -c 'echo $LEAK_TEST' on Unix) using the returned ProcessStartInfo
Assert child exits non-zero / output does not contain LEAK_TEST
SetEnvironment produces exactly the supplied env
Set LEAK_TEST=yes in process env
Construct driver, call SetEnvironment(new Dictionary<string,string>{ ["OTHER"] = "x" })
Spawn child that prints its env; assert LEAK_TEST is absent and OTHER=x is present
Concurrent drivers have independent envs
Driver A: SetEnvironmentVariable("K", "A")
Driver B: SetEnvironmentVariable("K", "B")
Spawn one child from each in parallel; assert each sees its own value for K
All three tests should fail on main and pass after the fix.
Scope
Pre-existing bug in MT infrastructure. Not caused by any in-flight task migration. Discovered during review of the Exec task
migration to TaskEnvironment API.
Activity
Fix MT TaskEnvironment leaking host process env vars to children (#13770
OvesN commentedon May 15, 2026
This is desired behavior