Skip to content

httpclient causes the risk of exhaustion of tcp resource pool #8509

Closed
@eanliu-cn

Description

@eanliu-cn

hello,
The following code will create httpclient every time you request it, and it is not explicitly released. In high concurrency scenarios, it may cause the tcp connection pool to be exhausted and new connections cannot be created. Is there any adjustment plan or other undiscovered processing to avoid long-term service exceptions

public HttpClient CreateClient(BoundConfiguration boundConfiguration)
	{
		if (boundConfiguration == null) throw new ArgumentNullException(nameof(boundConfiguration));

		var key = HttpRequestInvoker.GetClientKey(boundConfiguration);
		var handler = CreateHandler(key, boundConfiguration);
		var client = new HttpClient(handler, disposeHandler: false)
		{
			Timeout = boundConfiguration.RequestTimeout
		};
		return client;
	}

Official reference documents
https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions