Repository navigation
Fix ThreadAbort at first instruction of try block - #138306
Merged
janvorli merged 1 commit intoNov 26, 2026
Merged
Conversation
On Windows, when thread abort is thrown from APC activation callback, the exception handling is started from the ProcessCLRException and we consider the interrupted frame location as a call site and adjust the PC during EH. That prevents thread abort working correctly when the interruption happens at the first instruction of a try block. This change fixes it by detecting the interrupted frame in the ProcessCLRException and marking it with CONTEXT_EXCEPTION_ACTIVE to indicate that the context represents interrupted location and not a call site. Close dotnet#138208
|
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. |
jkotas
approved these changes
Nov 25, 2026
3 tasks
Member
Author
|
/backport to release/11.0 |
Contributor
|
Started backporting to |
Member
Author
|
/backport to release/10.0 |
Contributor
|
Started backporting to |
Contributor
|
@janvorli backporting to git am output$ git cherry-pick 7b1c31a126e50d8ae5590f6eb4ef85791c8dde68
Auto-merging src/coreclr/vm/exceptionhandling.cpp
Auto-merging src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/ControlledExecutionTests.cs
CONFLICT (content): Merge conflict in src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/ControlledExecutionTests.cs
error: could not apply 7b1c31a126e... Fix ThreadAbort at first instruction of try block (#138306)
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: Fix ThreadAbort at first instruction of try block
Using index info to reconstruct a base tree...
M src/coreclr/vm/exceptionhandling.cpp
M src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/ControlledExecutionTests.cs
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/vm/exceptionhandling.cpp
Auto-merging src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/ControlledExecutionTests.cs
CONFLICT (content): Merge conflict in src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/ControlledExecutionTests.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 Fix ThreadAbort at first instruction of try block
Error: The process '/usr/bin/git' failed with exit code 128 |
Contributor
|
@janvorli backporting to git am output$ git cherry-pick 7b1c31a126e50d8ae5590f6eb4ef85791c8dde68
Auto-merging src/coreclr/vm/exceptionhandling.cpp
CONFLICT (content): Merge conflict in src/coreclr/vm/exceptionhandling.cpp
Auto-merging src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/ControlledExecutionTests.cs
CONFLICT (content): Merge conflict in src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/ControlledExecutionTests.cs
error: could not apply 7b1c31a126e... Fix ThreadAbort at first instruction of try block (#138306)
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: Fix ThreadAbort at first instruction of try block
Using index info to reconstruct a base tree...
M src/coreclr/vm/exceptionhandling.cpp
M src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/ControlledExecutionTests.cs
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/vm/exceptionhandling.cpp
CONFLICT (content): Merge conflict in src/coreclr/vm/exceptionhandling.cpp
Auto-merging src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/ControlledExecutionTests.cs
CONFLICT (content): Merge conflict in src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/ControlledExecutionTests.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 Fix ThreadAbort at first instruction of try block
Error: The process '/usr/bin/git' failed with exit code 128 |
Member
|
ControlledExecution is best-effort feature for developer tools, it is not meant to be used in production code. I do not think this fix meets the backport bar. |
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.
On Windows, when thread abort is thrown from APC activation callback, the exception handling is started from the ProcessCLRException and we consider the interrupted frame location as a call site and adjust the PC during EH. That prevents thread abort working correctly when the interruption happens at the first instruction of a try block.
This change fixes it by detecting the interrupted frame in the ProcessCLRException and marking it with CONTEXT_EXCEPTION_ACTIVE to indicate that the context represents interrupted location and not a call site.
Close #138208