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

[WIP] Deadlock when creating typed HttpClient with DI and HttpClientFactory #40740

Closed
wants to merge 1 commit into from

Conversation

maryamariyan
Copy link
Member

Fixes: #35986

Perhaps a more general fix would be to correct the DI limitation for when a singleton instantiation required a transient that is to be lazily instantiated.

I am assuming here in order to just fix HttpClientFactory issue, that it is OK to get HttpMessageHandlerBuilder first hand in the constructor and whenever we want to lazily call CreateHandlerEntry, then the builder is already available (we basically move the GetRequiredService call out of lazy block to fix the deadlock.)

Then perhaps in 6.0 we could look to also fix the DI limitation that causes us to use this workaround.

cc: @davidfowl @tarekgh @eerhardt

- with DI and HttpClientFactory
@ghost
Copy link

ghost commented Aug 12, 2020

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

@@ -91,6 +92,7 @@ internal class DefaultHttpClientFactory : IHttpClientFactory, IHttpMessageHandle
}

_services = services;
_builder = _services.GetRequiredService<HttpMessageHandlerBuilder>();
Copy link
Member

Choose a reason for hiding this comment

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

        [](start = 0, length = 12)

does this will introduce any new memory allocations?

@maryamariyan
Copy link
Member Author

maryamariyan commented Aug 12, 2020

I should have created this as a draft PR. I'll add NO MERGE label instead.
Some tests need update and also seems like this might not be enough to fix the main issue. I'll update again in a bit.

@maryamariyan maryamariyan added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Aug 12, 2020
@maryamariyan maryamariyan changed the title Deadlock when creating typed HttpClient with DI and HttpClientFactory [WIP] Deadlock when creating typed HttpClient with DI and HttpClientFactory Aug 12, 2020
@maryamariyan
Copy link
Member Author

maryamariyan commented Aug 12, 2020

Closing PR. There's more calls to GetRequiredServices crossing the code path expressed in the issue that might cause a problem: https://github.com/dotnet/aspnetcore/blob/master/src/Middleware/HeaderPropagation/src/DependencyInjection/HeaderPropagationHttpClientBuilderExtensions.cs#L32

@karelz karelz added this to the 5.0.0 milestone Aug 18, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Extensions-HttpClientFactory NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deadlock when creating typed HttpClient with DI and HttpClientFactory
3 participants