-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Make HttpClientFactory implement IDisposable to clean up resources #115826
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: CarnaViire <[email protected]>
Co-authored-by: CarnaViire <[email protected]>
Tagging subscribers to this area: @dotnet/ncl |
src/libraries/Microsoft.Extensions.Http/src/DefaultHttpClientFactory.cs
Outdated
Show resolved
Hide resolved
…actory.cs Co-authored-by: CarnaViire <[email protected]>
src/libraries/Microsoft.Extensions.Http/src/DefaultHttpClientFactory.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Http/src/DefaultHttpClientFactory.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Http/src/DefaultHttpClientFactory.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Http/src/DefaultHttpClientFactory.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Http/src/DefaultHttpClientFactory.cs
Outdated
Show resolved
Hide resolved
...osoft.Extensions.Http/tests/Microsoft.Extensions.Http.Tests/HttpClientFactoryDisposeTests.cs
Outdated
Show resolved
Hide resolved
...osoft.Extensions.Http/tests/Microsoft.Extensions.Http.Tests/HttpClientFactoryDisposeTests.cs
Outdated
Show resolved
Hide resolved
...osoft.Extensions.Http/tests/Microsoft.Extensions.Http.Tests/HttpClientFactoryDisposeTests.cs
Outdated
Show resolved
Hide resolved
...osoft.Extensions.Http/tests/Microsoft.Extensions.Http.Tests/HttpClientFactoryDisposeTests.cs
Outdated
Show resolved
Hide resolved
...osoft.Extensions.Http/tests/Microsoft.Extensions.Http.Tests/HttpClientFactoryDisposeTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: CarnaViire <[email protected]>
src/libraries/Microsoft.Extensions.Http/src/ActiveHandlerTrackingEntry.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: CarnaViire <[email protected]>
src/libraries/Microsoft.Extensions.Http/src/ActiveHandlerTrackingEntry.cs
Outdated
Show resolved
Hide resolved
…logic Co-authored-by: CarnaViire <[email protected]>
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:If you need me to access, download, or install something from one of these locations, you can either:
|
...osoft.Extensions.Http/tests/Microsoft.Extensions.Http.Tests/HttpClientFactoryDisposeTests.cs
Show resolved
Hide resolved
…expired handler testing Co-authored-by: CarnaViire <[email protected]>
@copilot can you pls fix the races mentioned below:
|
Co-authored-by: CarnaViire <[email protected]>
... Fixed the race conditions in commit 62c0678. The changes address both identified issues:
The implementation now ensures proper coordination between disposal and all timer callbacks, preventing the scenarios where handlers could be leaked or timers recreated after disposal. |
Issue Description
When creating and disposing service providers that use HttpClientFactory, there's a memory leak because timers aren't properly cleaned up. This particularly affects scenarios where service providers are frequently created and disposed, such as in test environments.
The problem occurs because:
Changes Made
DefaultHttpClientFactory
implementIDisposable
interfaceStopTimer()
method toActiveHandlerTrackingEntry
to stop and dispose timersDispose()
method inDefaultHttpClientFactory
that:Benefits
Fixes #113494.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
pkgs.dev.azure.com
/home/REDACTED/work/runtime/runtime/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/runtime/runtime/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/runtime/runtime/artifacts/toolset/10.0.0-beta.25260.104.txt
(dns block)./.dotnet/dotnet build src/libraries/Microsoft.Extensions.Http/src/Microsoft.Extensions.Http.csproj
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.