HttpClient.Timeout 🟪 .NET

TaskCanceledException: The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing

The HTTP call took longer than HttpClient.Timeout (100 s default), so .NET cancelled it.

Seen on: .NET

Meaning

Slow APIs, large downloads, socket exhaustion from creating HttpClient per request, or DNS/connection problems end as TaskCanceledException. In .NET 5+ the message says it was the timeout rather than a user cancellation.

Common causes

  • Slow downstream service
  • New HttpClient per request (socket exhaustion)
  • Large responses buffered in memory
  • Network/DNS stalls

⚡ Quick fix

  1. Use IHttpClientFactory
  2. Set a sensible Timeout per client and add retries (Polly/resilience handlers)
  3. Stream large responses (HttpCompletionOption.ResponseHeadersRead)

Detailed fix by platform

C#

  1. csharp
    builder.Services.AddHttpClient<PaymentsClient>(c => c.Timeout = TimeSpan.FromSeconds(30))
        .AddStandardResilienceHandler();

How to diagnose

  1. Duration — How long the call runs
  2. Client — Created per request?
  3. Downstream — Its latency

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.