Closed JoshLove-msft closed 3 years ago
I found this article that seems to describe the situation we are running into - https://medium.com/criteo-engineering/net-threadpool-starvation-and-how-queuing-makes-it-worse-512c8d570527
In particular, using QueueUserWorkItem means that the work is queued to the global queue rather than the thread's local queue. If you read through the scenario, it explains why this might cause starvation when async code is being waited on synchronously (sync over async). The ideal fix would be to root out any place where we are doing sync over async.
See also https://github.com/Azure/azure-amqp/pull/188 which would address this and safe a few allocs. Apparently though we need to preserve the crash scenario of the thread pool :(
Some code, most likely from the user of the library, is blocking the threads. Please debug and fix such code. For thread pool scheduling, local vs global, we will use #188 for further evaluation.
Fixes https://github.com/Azure/azure-amqp/issues/190
I only updated this instance as I can consistently reproduce the issue I was running into in Service Bus by making this one change. I can update other instances of ActionItem.Schedule if you would like.