-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stack overflow from static constructors taking locks on Native AOT #113949
Comments
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
Cc @kouvel for an apparent recursion in locking |
This is when trying to access the gc static base of
And in the dumps I don't see thread usage that would make the
|
The most likely explanation is that it was locked when the code was executing. It was not locked by the time the dump got captured. |
There are no other threads in this particular case that would explain convoy, but if could definitely be a "too late" situation. The dump has 9 threads, only 3 with managed code in them. The others seem not to be doing much, but this one is 3559 frames deep, mostly in lock recursion. |
runtime/src/libraries/System.Private.CoreLib/src/System/Threading/WaitHandle.Windows.cs Line 49 in 9b091dc
System.Threading.Thread has static constructor due to this line
We either need to get rid of this static constructor; or get rid of the assumption that System.Threading.Thread does not have a static constructor in the above code. |
We can also force the Thread's cctor to run early, before we have other threads.
|
We could also move the There is a benefit on CoreCLR from storing this in a readonly static and computing in a cctor, since it can become a JIT constant. I do not think that is useful on NativeAOT, so any global location and any kind of initialization sequence would be ok. It does not even need to be computed before anything in particular (default |
My current preference would be to make |
BTW: We do not see it in our test runs since the Thread gets initialized very early in regular .exe mode before there is any multithreading. The crash can really only happen in dynamic library mode. The watson buckets above point to backgroundTaskHost.exe where the native AOT component runs in dynamic library mode. |
I would move Separately, we can choose to mark |
Nope. I think the choice was just because I think even with everything being
I think simply moving to |
I think one reason why we wanted the static to be on It was somewhat common pattern in the past where hot readonly statics would be initialized or "touched" on some less hot, but likely to happen early code path. |
Description
We're seeing quite a few hits across multiple WER buckets in the Microsoft Store, with similar stacktraces:
Here's a bunch of buckets with the same issue:
Opening this for tracking. @MichalStrehovsky and other folks are already looking into this internally (let me know if you'd like me to add you).
Configuration
The text was updated successfully, but these errors were encountered: