Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Net.Http: Closure causing excessive memory consumption #36979

Closed
filipnavara opened this issue May 25, 2020 · 1 comment · Fixed by #37021
Closed

System.Net.Http: Closure causing excessive memory consumption #36979

filipnavara opened this issue May 25, 2020 · 1 comment · Fixed by #37021
Assignees
Labels
Milestone

Comments

@filipnavara
Copy link
Member

Description

We analyzed memory dump from one of our testers which was showing excessive memory usage. The memory profiler showed us this:

image

Apparently the certificate validation callback in System.Net.Http request captures the HttpRequestMessage in a closure when establishing SSL connections:

sslOptions = sslOptions.ShallowClone(); // Clone as we're about to mutate it and don't want to affect the cached copy
Func<HttpRequestMessage, X509Certificate2?, X509Chain?, SslPolicyErrors, bool> localFromHttpClientHandler = mapper.FromHttpClientHandler;
HttpRequestMessage localRequest = request;
sslOptions.RemoteCertificateValidationCallback = (object sender, X509Certificate? certificate, X509Chain? chain, SslPolicyErrors sslPolicyErrors) =>
localFromHttpClientHandler(localRequest, certificate as X509Certificate2, chain, sslPolicyErrors);

In our case that happened to hold close to 70Mb of data from that particular request.

Configuration

.NET 3.1.200 (but the same code is present in master as of d0e2281)
Windows x64

Regression?

It likely is regression with SocketsHttpHandler when compared to the older WinHTTP handler.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Net.Http untriaged New issue has not been triaged by the area owner labels May 25, 2020
@ghost
Copy link

ghost commented May 25, 2020

Tagging subscribers to this area: @dotnet/ncl
Notify danmosemsft if you want to be subscribed.

@jkotas jkotas added the tenet-performance Performance related issue label May 25, 2020
@stephentoub stephentoub removed the untriaged New issue has not been triaged by the area owner label May 26, 2020
@stephentoub stephentoub added this to the 5.0 milestone May 26, 2020
@stephentoub stephentoub self-assigned this May 26, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
4 participants