Skip to content

[vs18.12] Make in-process ResolveAssemblyReference cancellable - #15206

Open
github-actions[bot] wants to merge 2 commits into
vs18.12from
backport/pr-14959-to-vs18.12
Open

github-actions[bot] wants to merge 2 commits into
vs18.12from
backport/pr-14959-to-vs18.12

Conversation

@github-actions

@github-actions github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

NET 11 Ask Mode

Description

RAR is a long running MSBuild task. When you cancel a build it needs to finish running before MSBuild exits (seconds-minutes).
This is perceived by customers as nonresponsivity/hang, especially in VS (which motivates this backport primarily since it's a top hang trace),
The experience in CLI is also confusing that after cancelation apparently nothing happens until RAR finishes.

This change adds a cancelation token that can be signaled in many places of the RAR task.

Regression? (was it working in a previous release or preview?)

No

Risk (see taxonomy)

Low

Backport of #14959 to vs18.12

JanProvaznik and others added 2 commits October 5, 2026 12:09
Fixes #12268

### Context

Canceling a build currently waits for ResolveAssemblyReference to finish
its work. This is particularly noticeable with large reference sets and
dependency graphs. Add cooperative cancellation for in-process RAR
without changing normal resolution behavior.

### Changes Made

- Implement `ICancelableTask` and propagate a cancellation token through
reference resolution, dependency traversal, conflict handling, and
output/logging loops. Handle this task's cancellation by returning
`false` without introducing cancellation diagnostics.
- Keep cache serialization uninterrupted once it starts, and balance the
affected tracing events when execution unwinds.
- Fix a pre-existing cache-isolation problem found while reviewing
cancellation safety: dependency remapping modified arrays and nested
remapping sets owned by the process-wide metadata cache. Remapping now
uses task-local results so later tasks do not inherit another
invocation's remappings.
- Add deterministic cancellation and recovery tests, including shared
folder-cache reuse, cold cache initialization, complete output metadata
comparisons, and positive cache-write controls. Document cancellation
semantics.

### Testing

- Full repository build and bootstrap sample build succeeded.
- Scoped RAR suites passed: 52 tests on `net11.0` and 433 on `net472`,
including 18 cancellation cases on each runtime. Four cache-isolation
regressions failed before the isolation fix and passed afterward.
- Local end-to-end `BuildManager` stress probe: 20,000 references across
64 search paths. Eight cancellation runs, triggered after RAR entered
closure computation, returned from `EndBuild()` in 57-73 ms. The
non-cancellable SDK RAR baseline on the same engine took 33 seconds
after cancellation.
- Local same-process recovery probe: 512 generated signed primary
assemblies, transitive dependencies, a real version conflict, and
related/satellite/serializer outputs. Cold and warm cancellation,
subsequent recovery, and timestamp invalidation preserved the expected
output paths and metadata. Cancellation preserved the existing state
file; timestamp invalidation updated it. CWD, PATH, and cultures
remained unchanged.

The end-to-end probes are local validation artifacts, not committed
integration tests.

### Notes

- In-process only; out-of-process RAR behavior and communication are
unchanged.
- Cancellation is cooperative, not a guarantee of bounded latency during
synchronous I/O or cache initialization. A cache write already in
progress may finish before the task returns `false`.
- No new warnings/errors or ChangeWave. Uncancelled resolution semantics
are preserved apart from preventing shared-cache contamination.

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b298eb1e-ffbe-414b-a2ad-f4255a11c4a2
@JanProvaznik

Copy link
Copy Markdown
Member

first dogfooding in vs main

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant