-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Fixes DI deadlock when resolving singletons #46157
Conversation
Tagging subscribers to this area: @eerhardt, @maryamariyan Issue DetailsIntroducing per singleton lock for the code path which resolves singletons. The repro test case in #35986 (comment) gets fixed with this change. TODO:
Fixes: #35986
|
I think you should try to use the call site itself as the lock for singletons |
1e01788
to
b9fb7cd
Compare
- Cleanup test
b9fb7cd
to
ea0c8dc
Compare
...ies/Microsoft.Extensions.DependencyInjection/tests/DI.Tests/ServiceProviderContainerTests.cs
Outdated
Show resolved
Hide resolved
Since this is pretty core logic that affects a lot of ASP.NET, is it possible to run all of ASP.NET's tests on this change before merging? How easy would that be @davidfowl @Tratcher @pranavkm ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How easy would that be
You could create a draft PR pointing to a build of this package and let the public CI do it's job. That shouldn't be too hard and could instill some confidence prior to merging this change.
...raries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteRuntimeResolver.cs
Outdated
Show resolved
Hide resolved
- Remove unrelated test - Code cleanup
...ies/Microsoft.Extensions.DependencyInjection/tests/DI.Tests/ServiceProviderContainerTests.cs
Outdated
Show resolved
Hide resolved
...ies/Microsoft.Extensions.DependencyInjection/tests/DI.Tests/ServiceProviderContainerTests.cs
Outdated
Show resolved
Hide resolved
…I.Tests/ServiceProviderContainerTests.cs Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
...ies/Microsoft.Extensions.DependencyInjection/tests/DI.Tests/ServiceProviderContainerTests.cs
Outdated
Show resolved
Hide resolved
As part of this exercise I downloaded the DI package from this PR (postfixed with -ci). But it's not straightforward to test the package against aspnetcore CI since they also need the package to point to a nuget source somewhere the CI can access. Testing the DI package against all aspnetcore projects locally is a bit of a hassle too. I'm working with @pranavkm on this and perhaps worst case we could merge this, and test off the published package from merge, and if problems occur then revert accordingly. |
as per @eerhardt 's recommendation updated the tests to use two ManualResetEvents so we can enforce the expected order of execution we want to test for deadlock. |
…ion to reliably test for deadlock.
Added an aspnetcore PR (dotnet/aspnetcore#29437) which triggers their tests on changes made here. UPDATE on status of the aspnetcore PR:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
The tests changes look good, and are deterministic now. Thanks for the good work here.
If github supported gifs, I would post a happy dance! This is a long standing issue with the DI container that has crippled many services. |
var lockType = RuntimeResolverLock.Root; | ||
bool lockTaken = false; | ||
|
||
if ((context.AcquiredLocks & lockType) == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pakrym notice that this check here is problematic and can no longer be used since we're taking a unique lock per singleton. We don't want to skip it here anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introducing per singleton lock for the code path which resolves singletons.
The repro test case in #35986 (comment) gets fixed with this change.
Fixes: #35986