-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Deadlock in ThreadPool.GetMaxThreads() during app start. #93175
Comments
Tagging subscribers to this area: @mangod9 Issue DetailsDescriptionWe found a deadlock that occurs transiently when our application is starting. From the call stack, the application is hanging on a call to Threadpool.GetMaxThreads(). Looking at the dump with repro with the 2 deadlocked threads, the deadlock involves locking around the ThreadPool type constructor and a lock taken in the EventListener class: The dump has been shared with the .NET team, filing this issue at the request of the .NET team for tracking. Reproduction StepsFrom David Mason (@davmason): Expected behaviorNo deadlock. Actual behaviorThere is a deadlock. Regression?No response Known Workarounds@davmason suggested creating the EventListener explicitly before calling ThreadPool.GetMaxThreads() as a workaround. I can confirm this works.
And then create one at the beginning of Main: Configuration.NET 6.0.20 Other informationNo response
|
@kouvel, have you seen this issue before? |
I haven't seen the issue before, but it makes sense and it sounds like @davmason has looked into it a bit. @davmason, is this something that can be generically fixed from the |
Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti |
The problem here is that we try to populate the counter values while holding the EventSource EventListenerLock. We should instead create the counters and not immediately populate the values, then let them populate when the timer fires on a different thread. |
For some reason we call ThreadPool.SetMinThreads on startup of the game server. Calling this function this early seems to put us at high risk of triggering the following deadlock bug in the .NET runtime: dotnet/runtime#93175 Given I have zero trust in whether this manual ThreadPool fuckery is even helpful, I'm just gonna nuke it and call it a day.
I know this isn't the most productive but I would just like to say that Rider automatically attaches EventPipe on app start now, which makes any code that runs ThreadPool's cctor extremely likely to deadlock just on startup. This is now forcing me to disable Rider's monitoring feature as I cannot start my app 5 times in a row from deadlocks. And I've had this happen before even on bog-standard ASP.NET Core apps. |
My team had the same problem with the rider, which led me here. Note: I needed a way to +1. If anyone else has the problem, make a thumbs-up on @PJB3005's comment. |
Description
There is a deadlock that occurs transiently when our .NET 6.0 application is starting. From the call stack, the application is hanging on a call to Threadpool.GetMaxThreads(). Looking at the dump with repro with the 2 deadlocked threads, the deadlock involves locking around the ThreadPool type constructor and a lock taken in the EventListener class:
The dump has been shared with the .NET team, filing this issue at the request of the .NET team for tracking.
Reproduction Steps
It's a not trivial repro. It involves running a .NET 6.0 app that calls into Threadpool.GetMaxThreads() during application startup and an external entity (on the same machine) triggering an ETW session that, in turn instantiates EventSource inside the application at the same time.
From David Mason (@davmason):
Expected behavior
No deadlock.
Actual behavior
There is a deadlock.
Regression?
No response
Known Workarounds
@davmason suggested creating the EventListener explicitly before calling ThreadPool.GetMaxThreads() as a workaround. I can confirm this works.
And then create one at the beginning of Main before calling ThreadPool.GetMaxThreads():
RuntimeEventListener listener = new RuntimeEventListener();
Configuration
.NET 6.0.20
Other information
No response
The text was updated successfully, but these errors were encountered: