Skip to content

Reacquire on Yield thread in TarDirectory and Untar - #15338

Merged
JanProvaznik merged 1 commit into
dotnet:mainfrom
am11:bugfix/tar-yield-reacquire-thread
Oct 22, 2026
Merged

JanProvaznik merged 1 commit into
dotnet:mainfrom
am11:bugfix/tar-yield-reacquire-thread

Conversation

@am11

@am11 am11 commented Oct 20, 2026

Copy link
Copy Markdown
Member

Both tasks called BuildEngine3.Yield() inside an async method and Reacquire() after an await with ConfigureAwait(false), so Reacquire could run on a thread-pool thread. TaskHost requires Reacquire on the thread that called Yield; the failed call left the request in the Yielding state and the scheduler failed with MSB0001.

Move Yield/Reacquire into the synchronous Execute() around the blocking wait. MockEngine now enforces the same rule, and regression tests run each task on a dedicated thread with a 1 MB file so the I/O completes asynchronously.

Fixes #15331

@am11
am11 temporarily deployed to copilot-pat-pool October 20, 2026 22:02 — with GitHub Actions Inactive
@am11
am11 temporarily deployed to copilot-pat-pool October 20, 2026 22:02 — with GitHub Actions Inactive
@am11 am11 changed the title Fix TarDirectory on a different thread than Yield Reacquire on Yield thread in TarDirectory and Untar Oct 20, 2026
Both tasks called BuildEngine3.Yield() inside an async method and
Reacquire() after an await with ConfigureAwait(false), so Reacquire
could run on a thread-pool thread. TaskHost requires Reacquire on the
thread that called Yield; the failed call left the request in the
Yielding state and the scheduler failed with MSB0001.

Move Yield/Reacquire into the synchronous Execute() around the blocking
wait. MockEngine now enforces the same rule, and regression tests run
each task on a dedicated thread with a 1 MB file so the I/O completes
asynchronously.

Fixes dotnet#15331

Co-authored-by: Cursor <[email protected]>
@am11
am11 force-pushed the bugfix/tar-yield-reacquire-thread branch from a6d47f5 to 436b6db Compare October 20, 2026 22:09
@JanProvaznik
JanProvaznik requested a review from AR-May October 21, 2026 14:11

@rainersigwald rainersigwald left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks. I support backporting to 11 servicing.

@JanProvaznik
JanProvaznik merged commit e5ccd1e into dotnet:main Oct 22, 2026
14 checks passed
@am11
am11 deleted the bugfix/tar-yield-reacquire-thread branch October 22, 2026 14:48
@am11

am11 commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

/backport to vs18.12

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to vs18.12 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@am11 an error occurred while backporting to vs18.12. See the workflow output for details.

@am11

am11 commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@JanProvaznik, could you please trigger the backport? I don't have permission in this repo.

@rainersigwald

Copy link
Copy Markdown
Member

/backport to vs18.12

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to vs18.12 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@rainersigwald backporting to vs18.12 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git cherry-pick e5ccd1e79e9e4799844a336c6eadc9ccd2b785f2

Auto-merging src/Tasks/TarDirectory.cs
CONFLICT (content): Merge conflict in src/Tasks/TarDirectory.cs
Auto-merging src/Tasks/Untar.cs
CONFLICT (content): Merge conflict in src/Tasks/Untar.cs
error: could not apply e5ccd1e79... Reacquire on Yield thread in TarDirectory and Untar (#15338)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"


$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Reacquire on Yield thread in TarDirectory and Untar
Using index info to reconstruct a base tree...
M	src/Tasks/TarDirectory.cs
M	src/Tasks/Untar.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Tasks/TarDirectory.cs
CONFLICT (content): Merge conflict in src/Tasks/TarDirectory.cs
Auto-merging src/Tasks/Untar.cs
CONFLICT (content): Merge conflict in src/Tasks/Untar.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Reacquire on Yield thread in TarDirectory and Untar
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

JanProvaznik added a commit that referenced this pull request Nov 9, 2026
Backport of #15338 to vs18.12.

Fixes #15331

Work item (Internal use): 

### Summary

`TarDirectory` and `Untar` called `BuildEngine3.Yield()` inside an async
method and `Reacquire()` after an `await` with `ConfigureAwait(false)`,
so `Reacquire` could run on a thread-pool thread. TaskHost requires
`Reacquire` on the thread that called `Yield`; the failed call left the
request in the Yielding state and the scheduler failed with MSB0001.
This moves `Yield`/`Reacquire` into the synchronous `Execute()` around
the blocking wait.

### Customer Impact

Builds using the `TarDirectory` or `Untar` tasks can fail intermittently
with MSB0001 (internal error) when the async I/O completes on a
different thread than the one that yielded.

### Regression?

N/A. `TarDirectory` and `Untar` are new in .NET 11, so there is no
earlier shipped behavior to regress from.

### Testing

Regression tests added in #15338 run each task on a dedicated thread
with a 1 MB file so the I/O completes asynchronously

### Risk

Low. The change is limited to the two tasks' Yield/Reacquire placement.

---------

Co-authored-by: Adeel Mujahid <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: JanProvaznik <[email protected]>
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.

TarDirectory task produces MSBUILD : error MSB1025: An internal failure occurred while running MSBuild

3 participants