Skip to content
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

[release/8.0] Fix a possible infinite wait for GC completion at process shutdown. #107844

Merged
merged 3 commits into from
Sep 19, 2024

Conversation

VSadov
Copy link
Member

@VSadov VSadov commented Sep 15, 2024

Fixes: #107800

This is a partial/minimal port of #103877.

Cooperative process cleanup is fragile and #103877 addresses many potential issues, however the change is not small and in parts works on top of 9.0 changes.
This is a port of a small part of the change to address a specific scenario that is known to affect end users.


Customer Impact

  • Customer reported
  • Found internally

Bug was reported by internal partners. In some relatively infrequent cases a worker process may get stuck at exiting.
Such "stuck" processes could become a nuisance, especially when the memory footprint of workers is very large.

Regression

  • Yes
  • No

Appears to be introduced in .NET 6 as the repro scenario passes with 5.0, but deadlocks in 6.0, 8.0 and early 9.0 previews

Testing

Added a targeted unit test.

Risk

Small.
The code already tries to detect if the process is shutting down. We just use a more reliable mechanism - a new Windows API introduced in Win10 (RtlDllShutdownInProgress)

The main concern is that there could be other similar issues.
The 9.0 fix addresses several more patterns similar to the one involved here. They may or may not result in actual failures and there is some added risk that proactive fixing of other areas may actually break something, which we decided not to do in a servicing fix.

VSadov and others added 2 commits September 15, 2024 16:07
…own on Windows (dotnet#103877)"

Fixes:107800

* Use RtlDllShutdownInProgress to detect process shutdown on Windows

Switching to cooperative mode is not safe during process shutdown on
Windows. Process shutdown can terminate a thread in the middle of the
GC. The shutdown thread deadlocks if it tries to switch to cooperative
mode and wait for the GC to finish in this situation.

Use RtlDllShutdownInProgress Windows API to detect process
shutdown to avoid waiting for GC completion when that may lead to deadlocks.
Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

src/coreclr/vm/vars.hpp Outdated Show resolved Hide resolved
Co-authored-by: Manish Godse <61718172+mangod9@users.noreply.github.com>
@VSadov VSadov added the Servicing-consider Issue for next servicing release review label Sep 17, 2024
Copy link
Member

@jeffschwMSFT jeffschwMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. we will take for consideration in 8.0.x

@jeffschwMSFT jeffschwMSFT added this to the 8.0.x milestone Sep 19, 2024
@rbhanda rbhanda modified the milestones: 8.0.x, 8.0.11 Sep 19, 2024
@rbhanda rbhanda added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Sep 19, 2024
@jeffschwMSFT jeffschwMSFT merged commit 1f0e1bd into dotnet:release/8.0-staging Sep 19, 2024
122 of 129 checks passed
@VSadov
Copy link
Member Author

VSadov commented Sep 19, 2024

Thanks!!

@VSadov VSadov deleted the fix107800 branch September 19, 2024 19:52
@github-actions github-actions bot locked and limited conversation to collaborators Oct 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-VM-coreclr Servicing-approved Approved for servicing release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants