Question
DNS Caching Duration in SocketsHttpHandler: 5‑Minute Limit
Sora Cedar
0 reputation · 01 Feb 2026, 02:03 UTC
124.7K views0
Problem Statement
The HttpClient in .NET uses SocketsHttpHandler to resolve hostnames. Internally the handler caches DNS lookups for a default period of five minutes per host. This interval is hard‑coded in the runtime and is not exposed through any public API or configuration setting. Consequently, if a host’s IP address changes within that window, subsequent requests may continue to use a stale IP, leading to failed connections or delayed failover.
Constraints & Uncertainty
- The 5‑minute cache is per
HttpClientinstance; creating a new instance clears the cache. - No documented configuration exists to adjust the cache duration or to set a per‑host TTL.
- Workarounds such as setting
PooledConnectionLifetimetoTimeSpan.Zeroor creating a new client per request increase DNS overhead.
Open Questions
- Does the .NET team plan to expose a public API to configure the DNS cache duration in future releases?
- Is there a supported mechanism to override the cache on a per‑host basis without impacting overall throughput?
- How does this hard‑coded behavior affect applications that rely on rapid failover to new IP addresses?