Skip to content

Catch all exceptions from Exit shutdown #12518

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

Merged
merged 2 commits into from
Jul 30, 2019

Conversation

jkotalik
Copy link
Contributor

@jkotalik jkotalik commented Jul 24, 2019

Fixes #7367 in 2.2.

If we fail to log to console due to an invalid handle, catch the exception no matter what.

Writing a test for this is really hard as I would need to muck with Console.* to make it throw.

Impact

This bug is to fix an issue with hosting aspnetcore in IIS In-process. On process shutdown, hosting tries to log to Console OnProcessExit. When hosting inprocess, once the main thread returns, we restore the original handle which the app originally had, making the old handle invalid. However, OnProcessExit runs after the main thread returns, which causes a race condition between the handle being invalid and the log to console. As this is on a background thread, it crashes the application.

Workaround

There are no work arounds. Once an event is added to AppDomain.ProcessExit, I don't believe it can be removed without the original event which is internal.

Risk

Very low. This only affects one call to Console.WriteLine and a cts.Cancel to catch all exceptions on process exit rather than only catching around the cts for an ODE.

cc @NickCraver

@jkotalik jkotalik requested review from analogrelay and Tratcher July 24, 2019 16:41
@analogrelay analogrelay added the Servicing-consider Shiproom approval is required for the issue label Jul 25, 2019
@analogrelay analogrelay added this to the 2.2.x milestone Jul 25, 2019
@analogrelay
Copy link
Contributor

@jkotalik can you fill in the shiproom "template" (I don't think there's a formal template anywhere) but basically we'll need details on customer impact and risk to the product. I'll send an email around to get approval.

@jkotalik
Copy link
Contributor Author

@anurse done.

@vivmishra vivmishra added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Jul 30, 2019
@vivmishra vivmishra modified the milestones: 2.2.x, 2.2.7 Jul 30, 2019
@vivmishra
Copy link

Approved for 2.2.7.
Check this is in as soon as ready.

@analogrelay
Copy link
Contributor

Respinning our CI check that failed for unrelated reasons, then I'll merge.

@analogrelay analogrelay merged commit c809b66 into release/2.2 Jul 30, 2019
@ghost ghost deleted the jkotalik/catchMoreExceptions branch July 30, 2019 19:55
@amcasey amcasey added the area-hosting Includes Hosting label Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-hosting Includes Hosting Servicing-approved Shiproom has approved the issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants