Skip to content

Conversation

janvorli
Copy link
Member

@janvorli janvorli commented Apr 9, 2024

When a foreign thread running in .NET process is killed or crashes due to some hardware exception, the .NET code that performs shutdown gets called and incorrectly expects the thread to be a thread that's registered with the runtime. It calls GetThread on it and then calls a method on the thread. That leads to an assert in debug builds and crash in release ones.

The function that is called is not needed for foreign threads though, so the fix is to skip calling it if the GetThreadNULLOk returns NULL (that means the thread is foreign and never registered with the runtime).

Close #95419

When a foreign thread running in .NET process is killed or crashes due
to some hardware exception, the .NET code that performs shutdown gets
called and incorrectly expects the thread to be a thread that's
registered with the runtime. It calls GetThread on it and then calls a
method on the thread. That leads to an assert in debug builds and crash
in release ones.

The function that is called is not needed for foreign threads though, so
the fix is to skip calling it if the GetThreadNULLOk returns NULL (that
means the thread is foreign and never registered with the runtime).
@janvorli janvorli added this to the 9.0.0 milestone Apr 9, 2024
@janvorli janvorli self-assigned this Apr 9, 2024
@janvorli janvorli merged commit 256191f into dotnet:main Apr 9, 2024
@janvorli janvorli deleted the fix-shutdown-on-foreign-thread branch April 9, 2024 18:55
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
When a foreign thread running in .NET process is killed or crashes due
to some hardware exception, the .NET code that performs shutdown gets
called and incorrectly expects the thread to be a thread that's
registered with the runtime. It calls GetThread on it and then calls a
method on the thread. That leads to an assert in debug builds and crash
in release ones.

The function that is called is not needed for foreign threads though, so
the fix is to skip calling it if the GetThreadNULLOk returns NULL (that
means the thread is foreign and never registered with the runtime).
@github-actions github-actions bot locked and limited conversation to collaborators May 10, 2024
@hoyosjs
Copy link
Member

hoyosjs commented Jun 2, 2025

/backport to release/8.0-staging

Copy link
Contributor

github-actions bot commented Jun 2, 2025

Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/15403960690

@github-actions github-actions bot unlocked this conversation Jun 2, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

libcoreclr signal handler may cause stack overflow SIGSEGV on 3rd party library threads
3 participants