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

[HttpClientFactory] Revert workaround for empty name HttpClient fallback #106269

Merged
merged 4 commits into from
Aug 13, 2024

Conversation

CarnaViire
Copy link
Member

@CarnaViire CarnaViire commented Aug 12, 2024

Revert the workaround from e958285, as #102654 was recently fixed.

Also adds the missing tripleslash docs.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@CarnaViire CarnaViire changed the title Revert workaround for empty name HttpClient fallback [HttpClientFactory] Revert workaround for empty name HttpClient fallback Aug 12, 2024
using System.Net.Http;
using Xunit;

namespace Microsoft.Extensions.DependencyInjection
{
public partial class HttpClientKeyedRegistrationTest
{
[Fact]
public void AddAsKeyed_EmptyNameHttpClientUpdated() // test for workaround for https://github.com/dotnet/runtime/issues/102654
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no value in keeping these tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None -- they were testing specifically the workaround logic that was removed.

Comment on lines +663 to +665
/// WARNING: Registering the client as a keyed <see cref="ServiceLifetime.Transient"/> service will lead to the <see cref="HttpClient"/> and <see cref="HttpMessageHandler"/>
/// instances being captured by DI as both implement <see cref="IDisposable"/>. This might lead to memory leaks if the client is resolved multiple times within a
/// <see cref="ServiceLifetime.Singleton"/> service.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems pretty sad.

However, this isn't specific to the IHttpClientFactory, and the same issue exists with any disposable service, right? It's just a new foot gun for us since we couldn't be transient before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep 🥲 https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection-guidelines#disposable-transient-services-captured-by-container

But there is hope that this might be finally addressed (in some way) in 10.0 (this was discussed during API review, as it was one of the main blockers for keyed-by-default). Also see #89755 (comment). Tracking issue: #36461 but we'd need to also create an additional one for per-service-descriptor opt-out.

Copy link
Contributor

@rokonec rokonec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ that this not become permanent.

CarnaViire and others added 2 commits August 12, 2024 21:40
…n/HttpClientBuilderExtensions.cs

Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants