ASP.NET Core Interview Question #240
How would you troubleshoot thread-pool starvation?
Senior ASP.NET Core Real-World Scenarios Senior Advanced
Quick Interview Answer
Look for increasing request latency and queued work while CPU is not necessarily saturated. Runtime counters, traces, and dumps can reveal thread-pool growth and blocked threads.
Detailed Explanation
Look for increasing request latency and queued work while CPU is not necessarily saturated. Runtime counters, traces, and dumps can reveal thread-pool growth and blocked threads.
A frequent cause is sync-over-async code such as .Result, .Wait(), or blocking I/O inside request processing. Long synchronous work can consume worker threads and prevent new requests from running promptly.
Use asynchronous APIs end-to-end for I/O, avoid unnecessary blocking, and move genuinely long CPU-bound work away from the request path when appropriate.
Code Example
// Avoid:
// var result = _client.GetAsync(url).Result;
// Prefer:
var result = await _client.GetAsync(url, cancellationToken);