-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -187,12 +187,20 @@ static async ValueTask Await(int i, ValueTask vt, List<object> toDispose) | |
| // No further changes to _state.Disposables, are allowed. | ||
| _disposed = true; | ||
|
|
||
| // ResolvedServices is never cleared for singletons because there might be a compilation running in background | ||
| // trying to get a cached singleton service. If it doesn't find it | ||
| // it will try to create a new one which will result in an ObjectDisposedException. | ||
| } | ||
|
|
||
| return _disposables; | ||
| if (IsRootScope && !RootProvider.IsDisposed()) | ||
| { | ||
| // 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(); | ||
tarekgh marked this conversation as resolved.
Show resolved
Hide resolved
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why cant this just noop internally?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
By "just noop internally", you mean adding the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. |
||
| } | ||
|
|
||
| // ResolvedServices is never cleared for singletons because there might be a compilation running in background | ||
| // trying to get a cached singleton service. If it doesn't find it | ||
| // it will try to create a new one which will result in an ObjectDisposedException. | ||
| return _disposables; | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.