Skip to content

fix(threading): Prevent crash during CRT shutdown when unregistering threads - #590

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/thread-unregister-shutdown-crash
Open

fix(threading): Prevent crash during CRT shutdown when unregistering threads#590
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/thread-unregister-shutdown-crash

Conversation

@sentry

@sentry sentry Bot commented Sep 3, 2026

Copy link
Copy Markdown

This PR addresses a crash (EXCEPTION_ACCESS_VIOLATION_READ / 0x0) occurring in Unregister_Thread_ID during application shutdown.

Root Cause:
The global ThreadList (DynamicVectorClass<ThreadInfoType*>) in Except.cpp is a CRT static object. During application exit, the CRT destroys static/global objects. If worker threads are still active and attempt to call Unregister_Thread_ID after ThreadList's destructor has run (which frees and nulls its internal data array), accessing ThreadList[i] results in a null pointer dereference.

Solution:
Introduced a volatile LONG s_crt_shutting_down flag. An atexit() callback (Mark_CRT_Shutdown) is registered to set this flag to 1 when CRT shutdown begins. atexit handlers execute before global object destructors, ensuring the flag is set in time.

Both Register_Thread_ID and Unregister_Thread_ID now check s_crt_shutting_down at their entry point. If the flag is set, they return immediately, preventing any access to the ThreadList global once CRT shutdown has commenced. This mirrors the approach taken in PR #483 to protect the thread list's critical section.

Fixes CLIENT-38C

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant