Skip to content

Fix hot reload cancellation race - #11401

Merged
Amaury Levé (Evangelink) merged 1 commit into
mainfrom
dev/amauryleve/fix-hotreload-cancellation-race
Sep 21, 2026
Merged

Amaury Levé (Evangelink) merged 1 commit into
mainfrom
dev/amauryleve/fix-hotreload-cancellation-race

Conversation

@Evangelink

@Evangelink Amaury Levé (Evangelink) commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Route ShouldRunAsync cancellation through the synchronized shutdown path so the shutdown flag is set before the semaphore waiter is released.
  • Remove the competing SemaphoreSlim.WaitAsync cancellation callback that could resume the waiter before the shutdown callback ran.
  • Strengthen the regression test to verify cancellation records shutdown and prevents a subsequent run.

The flaky failure was observed in #11387 on Linux/net9.0. The failure exposed a real callback-ordering race; this change does not assume how frequently that ordering occurs.

Validation

  • .\build.cmd -projects test\UnitTests\Microsoft.Testing.Extensions.UnitTests\Microsoft.Testing.Extensions.UnitTests.csproj -bl (0 warnings, 0 errors; MSBuild binlog generated)
  • .\.dotnet\dotnet.exe run --project test\UnitTests\Microsoft.Testing.Extensions.UnitTests\Microsoft.Testing.Extensions.UnitTests.csproj -f net9.0 --no-build -c Debug -bl:artifacts\log\Debug\HotReloadFixTest.binlog -- --filter "FullyQualifiedName=Microsoft.Testing.Extensions.UnitTests.HotReloadTests.ShouldRunAsync_WaiterIsBlockedAndCancellationIsRequested_StopsNextRun" --minimum-expected-tests 1 (1 passed)

Route cancellation through the synchronized shutdown path so the shutdown flag is set before the waiter is released.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 21, 2026 10:06
@github-actions github-actions Bot added the state/needs-review Awaiting review from the team. label Sep 21, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 21, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. labels Sep 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The focused synchronization fix resolves the reported race and is covered by meaningful regression assertions.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes the Hot Reload cancellation race by synchronizing shutdown signaling before releasing the waiter.

Changes:

  • Routes cancellation through RequestShutdown.
  • Removes competing semaphore cancellation.
  • Strengthens regression assertions.
Review coverage Cancellation ordering, caller behavior, framework compatibility, and regression coverage.
File Description
HotReloadHandler.cs Serializes cancellation and waiter release.
HotReloadTests.cs Verifies shutdown state and subsequent-run prevention.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Evangelink
Amaury Levé (Evangelink) merged commit b2f2655 into main Sep 21, 2026
41 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/amauryleve/fix-hotreload-cancellation-race branch September 21, 2026 11:20
@github-actions github-actions Bot removed the state/approved Proposal approved; ready for implementation. label Sep 21, 2026
@Evangelink

Copy link
Copy Markdown
Member Author

/backport to rel/4.4

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to rel/4.4: https://github.com/microsoft/testfx/actions/runs/35593656676

@github-actions

Copy link
Copy Markdown
Contributor

Amaury Levé (@Evangelink) backporting to rel/4.4 failed, the patch most likely resulted in conflicts:

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

Patch format detection failed.
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

@github-actions

Copy link
Copy Markdown
Contributor

Amaury Levé (@Evangelink) backporting to rel/4.4 failed, the patch most likely resulted in conflicts:

$ git am --continue

fatal: Resolve operation not in progress, we are not resuming.
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

12 similar comments
@github-actions

Copy link
Copy Markdown
Contributor

Amaury Levé (@Evangelink) backporting to rel/4.4 failed, the patch most likely resulted in conflicts:

$ git am --continue

fatal: Resolve operation not in progress, we are not resuming.
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

@github-actions

Copy link
Copy Markdown
Contributor

Amaury Levé (@Evangelink) backporting to rel/4.4 failed, the patch most likely resulted in conflicts:

$ git am --continue

fatal: Resolve operation not in progress, we are not resuming.
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

@github-actions

Copy link
Copy Markdown
Contributor

Amaury Levé (@Evangelink) backporting to rel/4.4 failed, the patch most likely resulted in conflicts:

$ git am --continue

fatal: Resolve operation not in progress, we are not resuming.
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

@github-actions

Copy link
Copy Markdown
Contributor

Amaury Levé (@Evangelink) backporting to rel/4.4 failed, the patch most likely resulted in conflicts:

$ git am --continue

fatal: Resolve operation not in progress, we are not resuming.
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

@github-actions

Copy link
Copy Markdown
Contributor

Amaury Levé (@Evangelink) backporting to rel/4.4 failed, the patch most likely resulted in conflicts:

$ git am --continue

fatal: Resolve operation not in progress, we are not resuming.
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

@github-actions

Copy link
Copy Markdown
Contributor

Amaury Levé (@Evangelink) backporting to rel/4.4 failed, the patch most likely resulted in conflicts:

$ git am --continue

fatal: Resolve operation not in progress, we are not resuming.
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

@github-actions

Copy link
Copy Markdown
Contributor

Amaury Levé (@Evangelink) backporting to rel/4.4 failed, the patch most likely resulted in conflicts:

$ git am --continue

fatal: Resolve operation not in progress, we are not resuming.
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

@github-actions

Copy link
Copy Markdown
Contributor

Amaury Levé (@Evangelink) backporting to rel/4.4 failed, the patch most likely resulted in conflicts:

$ git am --continue

fatal: Resolve operation not in progress, we are not resuming.
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

@github-actions

Copy link
Copy Markdown
Contributor

Amaury Levé (@Evangelink) backporting to rel/4.4 failed, the patch most likely resulted in conflicts:

$ git am --continue

fatal: Resolve operation not in progress, we are not resuming.
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

@github-actions

Copy link
Copy Markdown
Contributor

Amaury Levé (@Evangelink) backporting to rel/4.4 failed, the patch most likely resulted in conflicts:

$ git am --continue

fatal: Resolve operation not in progress, we are not resuming.
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

@github-actions

Copy link
Copy Markdown
Contributor

Amaury Levé (@Evangelink) backporting to rel/4.4 failed, the patch most likely resulted in conflicts:

$ git am --continue

fatal: Resolve operation not in progress, we are not resuming.
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

@github-actions

Copy link
Copy Markdown
Contributor

Amaury Levé (@Evangelink) backporting to rel/4.4 failed, the patch most likely resulted in conflicts:

$ git am --continue

fatal: Resolve operation not in progress, we are not resuming.
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

@github-actions

Copy link
Copy Markdown
Contributor

Amaury Levé (@Evangelink) backporting to rel/4.4 failed, the patch most likely resulted in conflicts:

$ git am --continue

fatal: Resolve operation not in progress, we are not resuming.
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

4 similar comments
@github-actions

Copy link
Copy Markdown
Contributor

Amaury Levé (@Evangelink) backporting to rel/4.4 failed, the patch most likely resulted in conflicts:

$ git am --continue

fatal: Resolve operation not in progress, we are not resuming.
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

@github-actions

Copy link
Copy Markdown
Contributor

Amaury Levé (@Evangelink) backporting to rel/4.4 failed, the patch most likely resulted in conflicts:

$ git am --continue

fatal: Resolve operation not in progress, we are not resuming.
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

@github-actions

Copy link
Copy Markdown
Contributor

Amaury Levé (@Evangelink) backporting to rel/4.4 failed, the patch most likely resulted in conflicts:

$ git am --continue

fatal: Resolve operation not in progress, we are not resuming.
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

@github-actions

Copy link
Copy Markdown
Contributor

Amaury Levé (@Evangelink) backporting to rel/4.4 failed, the patch most likely resulted in conflicts:

$ git am --continue

fatal: Resolve operation not in progress, we are not resuming.
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

@github-actions

Copy link
Copy Markdown
Contributor

Potential infinite loop guard hit. Stopping

Amaury Levé (Evangelink) added a commit that referenced this pull request Sep 21, 2026
…o rel/4.4) (#11404)

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
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.

3 participants