-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix leak caused by not disposing the scoped parent service provider #74261
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
Fix leak caused by not disposing the scoped parent service provider #74261
Conversation
|
Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection Issue DetailsFixes #73832
|
|
CC @ericstj |
...ies/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/ServiceProviderEngineScope.cs
Show resolved
Hide resolved
...s/Microsoft.Extensions.DependencyInjection/tests/DI.Tests/ServiceProviderEngineScopeTests.cs
Outdated
Show resolved
Hide resolved
...ies/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/ServiceProviderEngineScope.cs
Show resolved
Hide resolved
| // If this ServiceProviderEngineScope instance is a root scope, disposing this instance will need to dispose the RootProvider too. | ||
| // Otherwise the RootProvider will never get disposed and will leak. | ||
| // Note, if the RootProvider get disposed first, it will automatically dispose all attached ServiceProviderEngineScope objects. | ||
| RootProvider.Dispose(); |
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.
Why cant this just noop internally?
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.
It is simpler. no?
More code, more bugs :-) imagine in the future we add anything to the ServicePrivder dispose method.
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.
Why cant this just noop internally?
By "just noop internally", you mean adding the if check in ServiceProvider Dispose?
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.
Yep.
eerhardt
left a comment
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
|
/backport to release/7.0-rc1 |
|
Started backporting to release/7.0-rc1: https://github.com/dotnet/runtime/actions/runs/2905770618 |
|
/backport to release/6.0 |
|
Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/2905993688 |
Fixes #73832