We load-tested one Task.WaitAll in an ASP.NET Core controller, and in a 2-CPU container it fell over at eight requests a second
Everyone who writes C# knows the rule: don't call .Result or .Wait() in request code. Most of us also carry a quiet footnote to that rule, something like "but ASP.NET Core has no synchronization context, so it won't deadlock, and the thread pool grows anyway, so one blocking call in a dashboard endpoint is a style issue." We built a PR around exactly that footnote for the new C# section of the library, and before shipping it we put a number on it. At the traffic the requirements describe, the number was a minute and a half per request.
The PR
An operations dashboard polls a summary endpoint. The endpoint needs two independent numbers from two internal services: today's order totals (around 500 ms) and open helpdesk tickets (around 250 ms). The requirements say both calls run at the same time, so a summary should take as long as the slower one. About 400 screens refresh every 30 seconds, which is roughly 13 requests a second on one instance with 2 vCPUs. The PR looks like this:
Dashboard/DashboardController.cs
+29
It's honestly a decent-looking PR. The two calls really are started together, the cancellation token is passed through, the .Result reads come after the wait so they never block on their own, and the tests (one request at a time against instant fakes) are green. If you've been writing C# for a while, your eye goes to line 21, you think "hm, sync over async", and then the footnote kicks in.
What a trained eye flags here
Line 14 makes the action synchronous, and line 21 parks the request's thread-pool thread for the whole upstream wait, about half a second per request. Under the load the requirements declare, more requests are waiting at any moment than the pool has threads ready, and the pool only adds threads gradually. The comment that earns full marks names the blocking wait, says it bites under concurrent load rather than in a single request, and says what happens: the shared pool can starve, so summaries and other work that needs a pool thread queue up, which in our runs included the health endpoint. The fix is public async Task<ActionResult<DashboardSummary>> Summary(CancellationToken ct) with await Task.WhenAll(totalsTask, ticketsTask), then await each task for its result.
You can review this PR in the library, though now you know the answer.
What we measured
The harness runs the API on .NET 10 in a Docker container with a CPU limit (--cpus=2 or --cpus=8) and the runtime's default thread pool settings. With a CPU limit set, Environment.ProcessorCount is the limit rounded up, and the thread pool sizes itself from that. Both upstream services are faked as async waits of 500 ms and 250 ms, and a separate process fires summary requests at a fixed rate for 20 seconds while probing /health on the side. This was a laptop, not a cloud VM, so treat the exact seconds as one machine's numbers; the shape is the point. Same code, a few request rates, and the awaited version as a control:
At the rates we sampled, the transition was abrupt. With 2 CPUs and 4 requests a second the blocking version is fine: median 0.5 s, 95th percentile 1.4 s. At 6 requests a second the median still looks healthy at 0.75 s, but the 95th percentile is 6.9 s and the slowest summary took 7.9 s. That tail is the warning, and it's easy to miss on a dashboard that only plots the median. At 8 requests a second the median is 36 seconds. At the declared 13 requests a second it's 96 seconds, and the /health probe, which does nothing at all, waited up to 102 seconds, because it needs a pool thread like everyone else. The awaited version handled 30 requests a second with 2 CPUs at a 503 ms median and a 523 ms maximum.
Eight CPUs didn't fix it, they moved the cliff. 13 requests a second was fine there; at 30, 556 of the 600 requests were still waiting when the load generator's 180-second timeout gave up on them. In these runs the trouble started once request rate times half a second passed the CPU count: 6 requests a second is about three blocked requests at once against a default minimum of two pool threads (the tail went bad), 8 is four (the median went), and 30 is fifteen against eight. That's an observation from six blocking runs, not a general threshold (the awaited control at 30 requests a second is far past it and doesn't care), but it's a useful back-of-the-envelope for a review comment.
"But .NET 6 fixed this"
Partly, and the docs say exactly how much. Microsoft's thread pool starvation guide says that starting in .NET 6 the heuristics "scale up the number of ThreadPool threads much faster in response to certain blocking Task APIs", and in the very next sentence that "ThreadPool starvation can still occur with these APIs, but the duration is much briefer than it was with older .NET versions because the runtime responds more quickly." The same page describes what happens after the first fast ramp: further threads are added one to two per second. Our dashboard adds new blocked requests faster than that, and the upstream calls finish on timer callbacks or I/O completions, both of which run on pool threads, so the requests holding threads are waiting on work that is queued behind them. David Fowler's async guidance puts it bluntly: sync over async needs two threads to finish one operation, and it "usually leads to thread-pool starvation and results in service outages."
The detail that makes this nasty in production is the health probe. A probe that waits 102 seconds will blow through most configured probe timeouts, and depending on the failure threshold an orchestrator may restart the instance. The starvation guide warns that if an app is periodically restarted, each time the pool "is likely to enter a period of starvation where it's slowly increasing threads." A blocking endpoint can keep an instance in that loop, and the signature the guide tells you to look for is not a busy CPU: it's a thread count climbing slowly while CPU stays well under 100%.
Why it gets past review
The PR's own tests can't expose it: the code compiles without a warning and the tests send one request at a time to fakes that answer instantly. A developer machine usually misses it too, because the thread pool's minimum defaults to the processor count, and a laptop reporting 12 or 16 processors starts with a much higher floor than a 2-CPU container (we didn't test those counts, but the 8-CPU run at 13 requests a second was already fine). A staging environment that doesn't combine the production CPU limit with production-like traffic can miss it as well, and then the first sign is an instance that stops answering.
The same doc page mentions SetMinThreads as a way to temporarily work around blocking, and it's tempting when the pager goes off. It raises the minimum and can temporarily reduce starvation, but Microsoft warns that the extra scheduling, contention and context switching can degrade performance in other ways. The actual fix is the one in Microsoft's ASP.NET Core best practices: don't block on Task.Wait or Task.Result, and make controller actions asynchronous all the way down.
So in review, the question for every .Result, .Wait(), Task.WaitAll and GetAwaiter().GetResult() on a request path is not only "can this cause the classic deadlock" (ASP.NET Core has no synchronization context, so this pattern isn't prone to that one). It's "how many requests per second hit this, how long does it wait, and how many cores will it run on." Multiply the first two. If the answer is anywhere near the third, it's not a style comment, it's a blocker.
Try a review
19 ASP.NET Core PRs, each with one thing a reviewer should catch, or nothing at all.
The C# section is new this week: EF Core queries, minimal APIs, background services, HttpClient lifetimes. A free set in every stack, no signup, graded after your verdict.
Review a C# PR →