dotnet / corert

This repo contains CoreRT, an experimental .NET Core runtime optimized for AOT (ahead of time compilation) scenarios, with the accompanying compiler toolchain.
http://dot.net
MIT License
2.91k stars 511 forks source link

Stackoverflow doing WaitOneNoCheck #7979

Open mjsabby opened 4 years ago

mjsabby commented 4 years ago

DeviceDetection.Native!S_P_CoreLib_System_Threading_Lock__TryAcquireContended DeviceDetection.Native!S_P_CoreLib_System_Runtime_CompilerServices_ClassConstructorRunner__DeadlockAwareAcquire DeviceDetection.Native!S_P_CoreLib_System_Runtime_CompilerServices_ClassConstructorRunner__EnsureClassConstructorRun DeviceDetection.Native!S_P_CoreLib_System_Runtime_CompilerServices_ClassConstructorRunner__CheckStaticClassConstructionReturnThreadStaticBase DeviceDetection.Native!S_P_CoreLib_System_Threading_WaitHandle__WaitOneNoCheck DeviceDetection.Native!S_P_CoreLib_System_Threading_Lock__TryAcquireContended DeviceDetection.Native!S_P_CoreLib_System_Runtime_CompilerServices_ClassConstructorRunner__DeadlockAwareAcquire DeviceDetection.Native!S_P_CoreLib_System_Runtime_CompilerServices_ClassConstructorRunner__EnsureClassConstructorRun DeviceDetection.Native!S_P_CoreLib_System_Runtime_CompilerServices_ClassConstructorRunner__CheckStaticClassConstructionReturnThreadStaticBase DeviceDetection.Native!S_P_CoreLib_System_Threading_WaitHandle__WaitOneNoCheck DeviceDetection.Native!S_P_CoreLib_System_Threading_Lock__TryAcquireContended DeviceDetection.Native!S_P_CoreLib_System_Runtime_CompilerServices_ClassConstructorRunner__DeadlockAwareAcquire DeviceDetection.Native!S_P_CoreLib_System_Runtime_CompilerServices_ClassConstructorRunner__EnsureClassConstructorRun DeviceDetection.Native!S_P_CoreLib_System_Runtime_CompilerServices_ClassConstructorRunner__CheckStaticClassConstructionReturnThreadStaticBase DeviceDetection.Native!S_P_CoreLib_System_Threading_WaitHandle__WaitOneNoCheck

mjsabby commented 4 years ago

@jkotas @MichalStrehovsky do you know much about this?

MichalStrehovsky commented 4 years ago

My guess would be that accessing Thread.CurrentThread as part of the class constructor runner triggers a class constructor check.

Seems like internal static readonly int OptimalMaxSpinWaitsPerSpinIteration = 64; is the only thing the cctor initializes. This should really be a const. Submitted a pull request.

jkotas commented 4 years ago

@MichalStrehovsky change may help with this crash.

There is still a potential more fundamental problem: The regular Lock can end up using wait method overriden via synchronization context. The class constructor runner (and other similar places) should be better using LowLevelLock.