-
Notifications
You must be signed in to change notification settings - Fork 308
Conversation
@@ -59,7 +59,14 @@ public void Main(string[] args) | |||
|
|||
appShutdownService.ShutdownRequested.Register(() => | |||
{ | |||
serverShutdown.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.
Dispose should never throw. We should fix Kestrel
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.
Yes, we should fix Kestrel so it doesn't throw. That said, since Hosting will be interacting with 3rd party components here we should make it more defensive, especially when the consequence is a hang.
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.
Yeah what @Tratcher said. Need to fix both sides.
This isn't meant as a fix for the Kestrel bug. The problem it tries to solve is that the Dispose exception cannot be noticed at the moment: The I don't see it yet, but there sould be a better design here for exceptions during shutdown. Until then if a Dispose throws, this makes it possible to see the Exceptions at least. |
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine("TODO: Dispose threw exception:\n{0}\n{1}", ex.Message, ex.StackTrace); |
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.
We might want to use ILogger instead of going directly to the Console.
3b194b4
to
44d2b4d
Compare
catch (Exception ex) | ||
{ | ||
var logger = loggerFactory.Create<Program>(); | ||
logger.WriteError("TODO: Dispose threw exception:\n{0}\n{1}", ex.Message, ex.StackTrace); |
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.
Use Environment.NewLine
instead of \n
?
44d2b4d
to
ada59c7
Compare
Environment.NewLine, | ||
"TODO: Dispose threw exception:", | ||
ex.Message, ex.StackTrace); | ||
logger.WriteError(errorMessage); |
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 error message formatting doesn't look right. There is an overload that takes an exception object.
ada59c7
to
6cd5744
Compare
Looks good. |
|
@Tragetaschen has a CLA on file AFAIK /cc @Eilon I think this is good to merge |
Yup CLA is good. |
Catch exceptions while disposing
Kestrel#9 revealed a shutdown problem when an exception is thrown during the final Dispose. This exception would omit setting the ManualResetEvent and the runtime would essentially deadlock.
This PR makes an exception during Dispose visible.