Skip to content

Fix mutex cleanup crash on macOS/Linux#15684

Merged
nohwnd merged 2 commits into
microsoft:mainfrom
nohwnd:fix-mutex-cleanup-macos
Apr 16, 2026
Merged

Fix mutex cleanup crash on macOS/Linux#15684
nohwnd merged 2 commits into
microsoft:mainfrom
nohwnd:fix-mutex-cleanup-macos

Conversation

@nohwnd

@nohwnd nohwnd commented Apr 16, 2026

Copy link
Copy Markdown
Member

AssemblyCleanup may run on a different thread than AssemblyInitialize. On macOS/Linux the .NET runtime throws InvalidOperationException (not ApplicationException) when ReleaseMutex() is called from a non-owning thread. This widens the catch to handle both platforms.

AssemblyCleanup may run on a different thread than AssemblyInitialize.
On macOS/Linux the runtime throws InvalidOperationException (not
ApplicationException) when ReleaseMutex is called from a non-owning
thread. Widen the catch to handle both platforms.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 16, 2026 11:50
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adjusts integration test asset cleanup to avoid crashes when AssemblyCleanup runs on a different thread than AssemblyInitialize, which can cause Mutex.ReleaseMutex() to throw different exception types on macOS/Linux vs Windows.

Changes:

  • Adds explanatory comments about cross-thread ReleaseMutex() behavior across platforms.
  • Broadens the exception handling around ReleaseMutex() during cleanup.

Comment thread test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBuild.cs
@nohwnd
nohwnd enabled auto-merge (squash) April 16, 2026 13:30
@nohwnd
nohwnd merged commit fb4c973 into microsoft:main Apr 16, 2026
6 checks passed
This was referenced Jul 14, 2026
This was referenced Jul 17, 2026
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.

3 participants