[API Proposal]: HttpClient should consider adding a CloseIdleConnections() method #62256
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.Net.Http
Milestone
Background and motivation
Golang has this, see: https://pkg.go.dev/net/http#Client.CloseIdleConnections
This allows a user who knows that their HTTP usage has stopped, or at least decreased significantly, to force idle connections to be closed immediately instead of waiting for idle timeout.
Users can partially achieve this today by just disposing the HttpClient, which will cause all connections to be closed immediately; however, it will also cancel pending requests, so it is only viable if the client usage has completely stopped.
API Proposal
This probably requires a similar API at the HttpMessageHandler layer that the HttpClient can call into.
API Usage
Alternative Designs
As mentioned above, you can just Dispose the client entirely if you are done with it for now, and create a new one when you need it again.
Alternatively, you can set the idle timeout to a smaller value, which will cause idle connections to be scavenged more quickly.
Risks
No response
The text was updated successfully, but these errors were encountered: