Skip to content

Fix ControlledExecution.Run abort behavior on Linux and macOS - #136882

Merged
jkotas merged 6 commits into
mainfrom
copilot/fix-controlled-execution-abort
Nov 5, 2026
Merged

jkotas merged 6 commits into
mainfrom
copilot/fix-controlled-execution-abort

Conversation

Copilot AI commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Abort exception dispatch bypasses normal signal-handler return, leaving the activation signal blocked. It also bypasses the destructor that clears m_hasPendingActivation, causing subsequent abort requests to suppress signal delivery.

Fixes #136873

@azure-pipelines

azure-pipelines Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Copilot AI requested a review from jkotas November 3, 2026 02:31
Copilot AI requested a review from jkotas November 3, 2026 03:12
@jkotas
jkotas marked this pull request as ready for review November 3, 2026 03:13
Comment thread src/coreclr/vm/threadsuspend.cpp Resolved
Copilot AI requested a review from jkotas November 3, 2026 03:43
@jkotas jkotas changed the title [WIP] Fix ControlledExecution.Run abort behavior on Linux and macOS Fix ControlledExecution.Run abort behavior on Linux and macOS Nov 3, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @VSadov
See info in area-owners.md if you want to be subscribed.

@jkotas
jkotas requested review from VSadov and janvorli and a balanced review from Copilot November 3, 2026 03:45

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.

🔵 Needs a closer look

The Unix signal-mask changes interact with GC/debugger activation and require platform/runtime validation beyond the available static review and Linux-only execution report.

No open issues 🎉

What changed in this PR

This PR addresses repeated ControlledExecution.Run cancellation failures on Linux and macOS by restoring activation state before CoreCLR dispatches a thread-abort exception.

Changes:

  • Clear the pending-activation flag and unblock the activation signal before abort dispatch bypasses normal cleanup.
  • Add a process-isolated regression test that cancels execution three times on the same thread and checks each exception’s cancellation token.
File Description
src/​libraries/​System.Runtime/​tests/​System.Runtime.Tests/​System/​Runtime/​ControlledExecutionTests.cs Adds regression coverage for repeated cancellation on one thread.
src/​coreclr/​vm/​threadsuspend.cpp Resets Unix activation state before thread-abort dispatch.

Review effort: Balanced

@VSadov VSadov 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.

LGTM!

@jkotas
jkotas merged commit 5c99482 into main Nov 5, 2026
135 of 137 checks passed
@jkotas
jkotas deleted the copilot/fix-controlled-execution-abort branch November 5, 2026 17:08
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 6, 2026
BrzVlad added a commit that referenced this pull request Nov 10, 2026
Branching to the same instruction was not detected as an backwards
branch, so we didn't generate a safepoint. This means that a thread
running this loop couldn't be aborted and, worse than this, it would
prevent the app from ever stopping for GC.

Should fix `CancelRepeatedlyOnSameThread`, recently introduced in
#136882
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

ControlledExecution.Run aborts a thread only once on Linux and macOS: a second abort on the same thread never lands (Windows aborts every time)

4 participants