Uploaded an imageUploaded an imageUploaded an imageUploaded an imageI've run into an odd issue I can't figure out.
I'm running async code that's walking through a tree and running Http requests on some of the nodes. Problem is that the Http calls - although awaited - are not waiting. They silently die.
No error, no exception, no catch or finally handlers fire. It just doesn't wait for completion. The code after the await eventually fires but at that point the rest of the code is done.
This code is deep in an async stack, but... everything up the chain is awaited - there's nothing that should be running in parallel really even though the code is async.
But the code behaves as if the request calling is running in parallel (which it is not because it wouldn't work otherwise as results would get out of order).
But for some reason the Http await call (or what's upstream of it due to the Http call) is not awaiting and keeps running without waiting for completion.
It sounds like a missing await somewhere, but I can assure you that's not the case here. It works if I put a task.delay instead of the http code for example. It also works if I replace the Http call with a sync call (which has other issues).
Assistant
Whyawait HttpClient.SendAsync(…)can appear to “do nothing”
When aSendAsyncnever gets past theawait, it’s almost always one of three things:
['Symptom', 'What’s really happening', 'How to verify / fix']
['1\u202f–\u202fConnection‑pool starvationEarlier requests are still holding the socket, so the next request sits inHttpConnectionPool.SendWithVersionDetectionAndRetryAsyncwaiting for a slot.', 'You started several requests butdidn’t dispose or fully readthe responses, so the connection never returns to the pool (only two HTTP/1.1 connections per host by default). New requests hang indefinitely instead of throwing.', 'Quick test: throttle yourself to\u202f≤\u202f2 requests or dispose/read the content after each call – the hang goes away.Proper fix:await using var resp = await client.SendAsync(req, HttpCompletionOption.ResponseHeadersRead, ct); … await resp.Content.CopyToAsync(Stream.Null, ct);or simplyresp.Dispose()when you’re done.']
['2\u202f–\u202fA hidden sync/async mix further up the stackSome caller didtask.Wait()/.Resultor anasync voidtest method, causing a dead‑lock on the thread’s sync‑context.', 'The awaitable completes, but the continuation can’t resume because the thread is blocked.', 'Search the call‑tree for.Result,.Wait(), orasync void. In unit tests make the testasync Task, neverasync void. AddConfigureAwait(false)in your library layer to avoid UI/test sync‑context capture.']
['3\u202f–\u202fThe request is really still in flight(TLS handshake, proxy auth, DNS stall, etc.) but you ran off before the default 100\u202fs timeout.', 'You seeSslStream.ReadAsync/HttpConnection.SendAsyncCoreat the bottom of the stack – the request is legitimately stuck at the network layer.', 'Set an explicit timeout or cancellation token and log the resulting exception:using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30)); … await client.SendAsync(req, cts.Token);']
What your screenshots show
has dozens of frames likeSystem.Net.Http.HttpConnectionPool.→HttpConnection.WaitForConnectionAvailabilityAsync– classic sign ofconnection‑pool exhaustion.
The debug trace only logs the “Start Http request” line; the “finally” never fires because the code is waiting for a connection slot that never frees up.
keep theHttpResponseMessageinsettings.Responsebut never dispose it – every call leaks a connection until the pool is full.
has dozens of frames likeSystem.Net.Http.HttpConnectionPool.→HttpConnection.WaitForConnectionAvailabilityAsync– classic sign ofconnection‑pool exhaustion.
The debug trace only logs the “Start Http request” line; the “finally” never fires because the code is waiting for a connection slot that never frees up.
keep theHttpResponseMessageinsettings.Responsebut never dispose it – every call leaks a connection until the pool is full.
csharpCopy codestatic readonly HttpClient _http = new HttpClient
{
// optional: bump per‑server limit for lots of links
DefaultRequestVersion = HttpVersion.Version11
};
public async Task UrlAliveAsync(string url, CancellationToken ct = default)
{
using var req = new HttpRequestMessage(HttpMethod.Head, url);
code
// Important: ResponseHeadersRead so we can dispose immediately
await using var resp = await _http.SendAsync(
req,
HttpCompletionOption.ResponseHeadersRead,
ct).ConfigureAwait(false);
// Dispose frees the connection right here
return resp.IsSuccessStatusCode;
}
Eachrequest disposes itsHttpResponseMessage, the socket slot returns to the pool, and subsequentawaits resume normally.(If the payload matters, read/stream the content before disposing.)
Sanity‑check list for your code‑base
or fully readHttpResponseMessage/HttpContent.
Reuse a singleHttpClient(orIHttpClientFactory); don’t create/dispose per request.Microsoft Learn
Never mixasyncwith blocking calls (.Wait(),.Result).
Cap concurrency yourself (SemaphoreSlim) if you really need to fire many requests in parallel.
Add an explicit timeout or cancellation token so true network stalls surface as exceptions instead of silent hangs.
or fully readHttpResponseMessage/HttpContent.
Reuse a singleHttpClient(orIHttpClientFactory); don’t create/dispose per request.Microsoft Learn
Never mixasyncwith blocking calls (.Wait(),.Result).
Cap concurrency yourself (SemaphoreSlim) if you really need to fire many requests in parallel.
Add an explicit timeout or cancellation token so true network stalls surface as exceptions instead of silent hangs.
Do those, and the “requests start but never end” symptom disappears.
“Uploaded an imageUploaded an imageUploaded an imageUploaded an imageI've run into an odd….” Conversation with o3, from the ShareChat — Chatbot Conversations in the Wild dataset. The Chat Archive, 2026. https://thechatarchive.com/c/01m84tvg9m55dgv8q256n2t2rt