-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Exception in Dispose() prevents host from shutting down #51622
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @eerhardt, @maryamariyan Issue DetailsI'm not sure if this is a bug or not, but I could find it documented anywhere. To reproduce, run this code and hit Ctrl + C
After a few seconds. this is printed:
|
Looks like the issue here is that the runtime/src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.cs Lines 79 to 90 in 65bcece
runtime/src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.cs Lines 104 to 106 in 65bcece
The reason The following DI code captures the first exception from a service and returns it without disposes the rest of the services: Lines 106 to 132 in 65bcece
|
Isn't throwing from dispose a no-no? (https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1065) and https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose
I don't think we should do anything here (wrt to disposable in DI). As for the hang, that is a dupe of #50397 (sorta). One thing we can do is un-unify the shutdown paths between process exit and CLTR +C/SIGINT. If CTRL+C/SIGINT fires, we can disable blocking process exit until dispose. That logic is fraught with problems anyways but we can't handle the SIGTERM case on non-windows without this #50527. |
I'm not sure if this is a bug or not, but I could not find it documented anywhere.
When a service which implements IDisposable throws an exception in Dispose(), the host never shuts down.
To reproduce, run this code and hit Ctrl + C
After a few seconds. this is printed:
The text was updated successfully, but these errors were encountered: