-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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 IHost being disposed of twice #37631
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This pattern seems like a contradiction, it asserts two things:
A) Dispose should no-op if called a second time.
B) It's not safe to call IHost.Dispose a second time.
Why are different requirements being applied to WebApplication's implementation of Dispose vs IHost's? If IHost's implementation of Dispose does something similar then why does WA need any additional logic?
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.
The "only doing it once bit" I've taken from just the standard
IDisposable
implementation pattern, but I think your question is really getting at the fact that I'm not sure exactly why this has started happening in RC2.At first I thought it was because
DeferredHost
actually was disposing twice in the same call, but it turned out I'd just misread the code. After that, it just seemed correct to have both these types (which were to only two I looked at in this repo) follow that pattern anyway.You're right though that
Host
itself also doesn't follow this pattern either, which is why I don't think this change is the fix as two different objects are disposing the same underlyingIHost
twice overall, so even with these guards it's still disposed of twice, just from two different places that don't know about each other.https://github.com/dotnet/runtime/blob/8608dca513a9be1f1bfc6a31deb8b22639a33d9f/src/libraries/Microsoft.Extensions.Hosting/src/Internal/Host.cs#L162-L195
Maybe the fix is to instead (or also) make a similar change there too?
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.
Even
Host.DisposeAsync()
is just disposing other types. Should AzureKeyVaultConfigurationProvider be fixed so dispose can be called more than once?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.
I opened a PR for that, not sure when it'll be available in NuGet to consume though. Azure/azure-sdk-for-net#24769
I think at this point this PR has devolved into more of an "issue" (what changed to make this start happening, and is that bad?) as what I originally thought was the fix was a red-herring.
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.
I think we should probably close this then. I'm not a big fan of having
_dispose
flags in every class that just disposes its fields in Dispose() unless it fixes some sort of pervasive problem.