الانتقال إلى المحتوى
.NETPerformance· 7 دقائق للقراءة

Blocking on .Result Hurts ASP.NET Core Even Without a Deadlock

There's no SynchronizationContext to deadlock on, but every blocked call parks a thread pool thread. Under load the pool runs dry, requests queue, and even a health check waits seconds.

ReadIn

مقال كل يوم يفرق معاك

22 نوفمبر 2026
  • كاتب موثّق
  • .NET 10
محتويات المقال

A pricing service calls an exchange-rate API through a synchronous method, ToLocal, because the interface it implements was written years ago. Inside, one line does the bridging: rates.GetRateAsync(currency).GetAwaiter().GetResult(). In review, someone asks about deadlocks, and the answer is correct: ASP.NET Core has no synchronization context, so there's nothing to deadlock on. Tests pass, normal traffic is fine. Then, after each morning deploy, requests that usually take 200 ms take seconds, health checks time out, and the orchestrator starts restarting instances. CPU stays low, and there's no exception to look at.

The common misconception

The belief: blocking on a task is dangerous only because of deadlocks. Deadlocks need a , ASP.NET Core doesn't have one, so .Result, .Wait() and GetAwaiter().GetResult() are safe there, just a little wasteful.

Half of this is true, which is why it's so persistent. The famous deadlock comes from UI apps and classic ASP.NET, where an await must resume on the very thread that's blocked waiting for it. That can't happen in ASP.NET Core. The code returns the right value, and at low traffic it's as fast as the async version. One thread waiting 200 ms sounds like a rounding error.

The cost isn't one thread, though. It's one thread per request in flight, taken from a shared pool that grows slowly on purpose.

What actually happens

A blocked thread is a lost thread

ASP.NET Core runs every request on the . With await, the thread goes back to the pool while the HTTP call is in flight and serves other requests. With , it stays parked until the call returns, doing nothing. Fifty concurrent requests to a 200 ms call need about fifty threads instead of a handful. The best practices page is direct about the result: many blocking calls "lead to Thread Pool starvation and degraded response times".

The pool adds threads slowly, by design

The pool creates threads on demand up to a minimum, which by default equals the processor count. Past that point it creates threads gradually, because too many threads compete for the CPU. Since .NET 6 it reacts faster when threads block on a task: some extra threads come without delay, then each new one waits a little longer, and when physical memory is short, injection slows down further. Until enough threads exist, new requests wait in the queue, including ones that would finish instantly.

The work that releases them waits in the same queue

The blocked thread is waiting for a task to complete, and completing it means running the code after the await inside GetRateAsync, its . That code needs a pool thread as well, and it's queued behind incoming requests. Every new thread the pool adds may pick up a new request and block too. It's a deadlock in slow motion that only ends when the pool has added enough threads. That's .

What it looked like in a test

On .NET 10, with the runtime limited to 4 processors and 50 concurrent clients calling a 200 ms dependency:

  • Async: p95 latency 219 ms, 8 to 9 pool threads, a /health endpoint answered in about 1 ms.
  • Blocking: the first requests took up to 7.3 seconds, and /health, which returns a constant, took 7.3 seconds too. The pool grew to 56 threads before latency settled. GetAwaiter().GetResult() behaved the same.
  • One run in four: 50 threads blocked, work still queued, and nothing completed for 56 seconds. The test machine was close to its memory limit, where the docs say injection slows. With 200 clients, the blocking version finished nothing within the two-minute timeout.

That's why it shows up after deploys and scale-outs: every fresh process starts with a small pool and goes through the climb again.

The fix: async all the way up

The same service and endpoint, before and after:

C# Program.cs
var builder = WebApplication.CreateBuilder(args);builder.Services.AddHttpClient<RatesClient>();builder.Services.AddScoped<PriceCalculator>();var app = builder.Build();app.MapGet("/quote", (decimal amount, string currency, PriceCalculator calc) =>    calc.ToLocal(amount, currency));app.Run();public sealed class PriceCalculator(RatesClient rates){    public decimal ToLocal(decimal amount, string currency)    {        // No deadlock, but this pool thread is parked until the call returns        var rate = rates.GetRateAsync(currency).GetAwaiter().GetResult();        return amount * rate;    }}

The change spreads upward: ToLocal becomes ToLocalAsync, its interface returns Task<decimal>, and every caller awaits it. That's the real cost of the fix, and it's why blocking calls survive in old interfaces.

MythReality
No SynchronizationContext, so .Result is safeNo classic deadlock, but each call parks a pool thread for its whole duration
The pool adds threads whenever they're neededIt adds them gradually, slower when memory is short; requests queue meanwhile
GetAwaiter().GetResult() is the safe way to blockIt blocks the same way; it only throws the original exception instead of an AggregateException
Task.Run(...).Result moves the blocking elsewhereThe request thread still blocks, and the inner work takes a second pool thread
Raising SetMinThreads fixes itIt shortens the climb by keeping many more threads around, each with its own stack

How to apply it in your project

  1. Find the blocking callsSearch for .Result, .Wait(), GetAwaiter().GetResult() and Task.WaitAll. Turn on analyzer rule CA1849, which is off by default in .NET 10; it flags these calls inside methods that return a Task. Calls in synchronous methods still need the text search.
  2. Make the chain async, starting at the bottomChange the method that blocks to return a Task, await it, and pass a CancellationToken. Then fix each caller up to the endpoint. Where an interface forces a synchronous signature, add an async version and move callers to it.
  3. Replace the framework calls that blockSome blocking hides in framework calls. The docs list Request.Form and a synchronous ReadToEnd on the request body as sync over async; use await Request.ReadFormAsync() and ReadToEndAsync instead.
  4. Load test a cold processStarvation hides at low traffic and in warm processes. Start a fresh instance, send many concurrent requests right away, and watch latency and thread count with dotnet-counters.

Key takeaways

  • No SynchronizationContext means no classic deadlock, not safe blocking: every blocked call holds a pool thread.
  • The continuation that would release a blocked thread needs a pool thread too, so blocking under load starves the pool.
  • The pool grows gradually and more slowly under memory pressure; until it catches up, every request waits, even trivial ones.
  • GetAwaiter().GetResult(), Task.Run(...).Result and SetMinThreads don't fix it; awaiting all the way up does.
  • Look for a climbing thread count with low CPU, and find the blocked frames with dotnet-stack.

📚 المصادر

  1. ASP.NET Core Best Practices: Avoid blocking calls — Microsoft Learn
  2. Debug ThreadPool starvation — .NET, Microsoft Learn
  3. The managed thread pool — .NET, Microsoft Learn
  4. Threading config settings: thread injection in response to blocking — Microsoft Learn
  5. CA1849: Call async methods when in an async method — Microsoft Learn

التعليقات (0)