dotnet resource_error ai_generated true

SocketException: An existing connection was forcibly closed

ID: dotnet/http-client-factory-leak

Also available as: JSON · Markdown
80%Fix Rate
84%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
8 active

Root Cause

HttpClient DNS caching or socket leak.

generic

Workarounds

  1. 92% success Use IHttpClientFactory with managed lifetime
  2. 88% success Set PooledConnectionLifetime to 2-5 minutes

Dead Ends

Common approaches that don't work:

  1. Dispose HttpClient after every use 82% fail

    Creates new connections each time

  2. Use static HttpClient with infinite lifetime 78% fail

    DNS changes never picked up