Skip to content

Fix suspend/abort of while (true) { } on interpreter - #137216

Merged
BrzVlad merged 1 commit into
dotnet:mainfrom
BrzVlad:fix-clrinterp-suspend
Nov 10, 2026
Merged

BrzVlad merged 1 commit into
dotnet:mainfrom
BrzVlad:fix-clrinterp-suspend

Conversation

@BrzVlad

@BrzVlad BrzVlad commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

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

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.
@azure-pipelines

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: @JulieLeeMSFT, @BrzVlad, @janvorli
See info in area-owners.md if you want to be subscribed.

@BrzVlad

BrzVlad commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

/ba-g unrelated failure in non-interp job

@BrzVlad
BrzVlad merged commit 0cf945b into dotnet:main Nov 10, 2026
110 of 112 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 11, 2026
pcshrosbree added a commit to pcshrosbree/runtime that referenced this pull request Nov 25, 2026
…itch

The interpreter emits a safepoint at method entry and before a backward
branch. Two other ways of closing a loop got none, so a thread spinning in
such a loop was never suspended, and a GC on another thread did not
complete:

- a backward leave, which closes a loop whose body ends in a protected
  region;
- a switch with a backward target.

Emit the safepoint, and the sampling point, for both through a helper that
the backward branch now uses too.

A branch to itself had the same problem (dotnet#135465). dotnet#137216 fixed it on main
in the same way, so this change keeps that check and moves its safepoint
into the helper.

Add the regression test src/tests/Regressions/coreclr/GitHub_135465. It runs
each kind of loop (a branch to itself, a backward leave, a backward leave
through a finally, and a backward switch) on a background thread and checks
that a GC completes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants