TimeoutException caused by connection pool exhaustion in EF Core
0 reputation · 10 Aug 2021, 19:34 UTC
Problem
In a high‑concurrency ASP.NET Core application using EF Core 8, a TimeoutException occasionally bubbles up from DbConnection.Open. The exception stack shows the ADO.NET provider throwing due to the underlying connection pool being exhausted. The application uses DbContextPool with default settings, and the connection string contains Pooling=true;Max Pool Size=100. The errors appear intermittently, not consistently on every request.
Constraints & Uncertainty
The exact cause of the pool exhaustion is unclear. Possibilities include:
- Transient spikes in request volume that briefly exceed the pool size.
- Improper disposal of
DbContextinstances leading to leaked connections. - Interaction between EF Core’s internal pooling and the ADO.NET pool limits.
There is no current telemetry on pool usage or connection churn, and the application’s transaction scopes vary between short and long operations.
Key Questions
- What ADO.NET and EF Core metrics should I monitor to confirm that the pool is being exhausted?
- How can I distinguish between a genuine connection‑pool timeout and a different transient network error in the exception stack?
- What best‑practice adjustments to
DbContextPoolconfiguration or connection string settings can mitigate intermittent pool exhaustion?