Draft
Guard ActivelyBuildingTargets removal against stale request cleanup after cancellation timeout#14732
Conversation
Contributor
|
Hello @copilot, I noticed that you’re changing an .swr file or any file under src/Package/MSBuild.VSSetup.. Please make sure to validate this change by an experimental VS insertion. This is accomplished by pushing to an exp/* branch, which requires write permissions to this repo. |
Co-authored-by: AR-May <67507805+AR-May@users.noreply.github.com>
Co-authored-by: AR-May <67507805+AR-May@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix caching issue after stale /mt request cleanup
Guard ActivelyBuildingTargets removal against stale request cleanup after cancellation timeout
Aug 18, 2026
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.
Context
BuildManager.Reset()clearsBuildRequestConfiguration.ActivelyBuildingTargetsat end-of-build, butTargetBuilderremoved entries from that table by target name only, ignoring the owning request ID. If a request's cancellation times out while the task keeps running, it can resume later and remove an entry that a newer request (reusing the same retained configuration) has since recorded for the same target name — making the configuration falsely appear inactive. This can let another request build the same target concurrently, corrupt circular-dependency detection, or letCacheIfPossible()cache theProjectInstancewhile it's still in use.Changes Made
BuildRequestConfiguration: addedRemoveActivelyBuildingTargetIfOwnedBy(targetName, globalRequestId), which only removes the entry if it is still recorded as owned by the given request ID.TargetBuilder: replaced all 4 unconditionalActivelyBuildingTargets.Remove(name)call sites (end-of-build stack cleanup, error-execution catch, target-completed cleanup, dependency-pop-on-failure) with the new guarded removal.Testing
Added a unit test in
BuildRequestConfiguration_Testsverifying a stale owner's removal is a no-op while the current owner's removal succeeds. ExistingTargetBuilder_TestsandRequestBuilder_Testscontinue to pass.Notes
No behavioral change for the common case where the current request still owns the entry; this only prevents cross-request interference during the stale-cleanup race described in the issue.