Skip to content

Node are reused between builds with different temp directories #13594

@mdiluz

Description

@mdiluz

Issue Description

Two separately invoked builds with different temporary directories in their environment can share their nodes and therefore each other's temporary directory locations, causing unexpected behaviour.

Steps to Reproduce

Build two projects at a similar time with the same msbuild.exe bit with different temdirs set, following steps similar to the following:

  1. Start Build A with tmpdir TMPA
  2. Start Build B with tmpdir TMPB
  3. Wait for Build A to finish
  4. Delete TMPA
  5. Observe warnings and/or errors produced by Build B

We think we have also seen this reproduce when running builds A and B in sequence, but it appears to be much harder to reproduce if so.

This can take a few tries as node reuse is not deteministic and relies on relative timing and other factors. The projects I have reproduced this on are not shareable, But this should reproduce even for template projects, as long as the build nodes are long lived enough to trigger node re-use between the two processes.

Workarounds that appears to work for our case - either set MSBUILDDISABLENODEREUSE=1 or set MSBUILDNODEHANDSHAKESALT differently for each build.

Expected Behavior

A build should only ever use the specified temp directory in it's environment.

Deleting a unqiue temporary directory used for one build should not cause warnings or errors in a different build invocation using a different temporary directory.

Actual Behavior

Issues are encountered can be "harmless" in the form of warnings (e.g. MSB5018: Failed to delete the temporary file) or fatal but often generic errors (e.g. The system cannot find the path specified) that do not point to any specific missing file and result in a failed build.

Analysis

Each msbuild node uses a path within it's found tempir. The handshake for node reuse is calculated here and can be seen to not take into account the location of that chosen temp directory.

Put together this leads to a situation where two similar builds A and B can be started using different temp directories (e.g. by setting TMP), but each build can reuse nodes from eachother. If build A is done, it can be assumed that it's particular user temp directory can be cleared, but this will cause issues for build B which is using nodes originally created by build A.

Note that older versions (e.g. v17.14) the two nodes would be using the same MSBuildTemp directory within the environment temporary directory. Newer versions since #12688 use unique dirs per node, but as the parent is still pulled in from the environment this doesn't appear to affect the repro.

Best guess fix is the handshake should also include the temp directory and potentially other environment values.

Versions & Configurations

Largely seen on v17.14 and reproduced in v11.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions