Repository navigation
Fix suspend/abort of while (true) { } on interpreter - #137216
Merged
Merged
Conversation
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: 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. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @BrzVlad, @janvorli |
janvorli
approved these changes
Nov 9, 2026
Member
Author
|
/ba-g unrelated failure in non-interp job |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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