Skip to content

Fix hangdump on macOS - #7005

Merged
Youssef Fahmy (Youssef1313) merged 6 commits into
mainfrom
dev/ygerges/addtest-hangdump
Dec 1, 2025
Merged

Youssef Fahmy (Youssef1313) merged 6 commits into
mainfrom
dev/ygerges/addtest-hangdump

Conversation

@Youssef1313

@Youssef1313 Youssef Fahmy (Youssef1313) commented Nov 27, 2025 •

Copy link
Copy Markdown
Member

Today, we use mutex for the interprocess communication between test host and test host controller. The flow goes as follow:

  1. The test host creates the mutex, and initially owns it.
  2. The test host controller requests ownership of the mutex, with a timeout matching the hangdump timeout.
  3. When the test host has any activity, it releases the mutex (with the intention of unblocking the test host controller)
  4. The test host controller now unblocks and starts owning the mutex. Then it immediately releases the mutex back and requests it again with the hangdump timeout.
  5. The test host would have already requested ownership of the mutex again and will have it after the test host controller releases it.
  6. We go through cycles of exchanging ownership of the mutex, until the test host has no activity for period > dump timeout. At this point, the test host controller won't be able to get ownership of the mutex in the given time and will detect a timeout.

This flow works well on Windows, but never works well on macOS. What we see on macOS is that the test host always gets the ownership of the mutex. Here, the test host releases the mutex and re-requests its ownership again. The test host controller is also requesting ownership of the mutex. Due to implementation differences of named mutex in .NET between Windows and macOS, what we see on Windows is that the ownership always gets swapped. But on macOS, it can happen that only the test host is always getting the ownership. This means that we end up in a situation where hang dump will be detected but no actual hang is happening.

This PR changes the implementation to avoid the use of a named mutex altogether, which also has problems on Mono and NativeAOT -> dotnet/runtime#110348.

The new implementation relies on named pipe and a timer. Whenever the test host has activity, we send that through named pipe to the test host controller. The test host controller keeps resetting a timer when activity is received. When the timer callback fires, we start taking a dump.

Note: to my best guess, macOS has very different mutex implementation that uses file locks. See https://github.com/dotnet/runtime/blob/c3d9ccd34e63d7b383735af55c9bd94f55664996/src/coreclr/pal/src/include/pal/mutex.hpp#L129-L130

This PR fixes the root cause of #6998, but keeping that issue open until this PR flows to main and we bring back hangdump on macOS.

@Youssef1313
Youssef Fahmy (Youssef1313) force-pushed the dev/ygerges/addtest-hangdump branch 2 times, most recently from d3142b1 to dc981f9 Compare November 28, 2025 20:36
@Youssef1313 Youssef Fahmy (Youssef1313) changed the title Add test for hangdump Fix hangdump on macOS Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants