runtime: Compiler crashes when failing to release Mutex

Error Message

Fill the error message using step by step known issues guidance.

{
  "ErrorMessage": "ReleaseMutex failed. WaitOne Id:",
  "BuildRetry": true,
  "ErrorPattern": "",
  "ExcludeConsoleLog": true
}

Example error:

/__w/1/s/.packages/microsoft.net.compilers.toolset/3.10.0-4.21273.6/tasks/netcoreapp3.1/Microsoft.CSharp.Core.targets(71,5): error MSB3883: Unexpected exception:  [/__w/1/s/src/tasks/installer.tasks/installer.tasks.csproj]
/__w/1/s/.packages/microsoft.net.compilers.toolset/3.10.0-4.21273.6/tasks/netcoreapp3.1/Microsoft.CSharp.Core.targets(71,5): error : One or more errors occurred. (ReleaseMutex failed. WaitOne Id: 14 Release Id: 14) [/__w/1/s/src/tasks/installer.tasks/installer.tasks.csproj]

Build: https://dev.azure.com/dnceng/public/_build/results?buildId=1161146&view=logs&j=1a1e7658-955a-5bfe-8410-74fa4a1a1fbf&t=9528cbd6-a8dd-5006-9c48-38938c12a3af

Configuration: CoreCLR Product Build Linux arm64 release

cc @jkotas @jaredpar @stephentoub

Known issue validation

Build: 🔎 Result validation: ⚠️ Provided build not found. Provide a valid build in the “Build: 🔎” line. Validation performed at: 9/15/2023 5:21:46 PM UTC

Report

Build Definition Step Name Console log Pull Request
2340504 dotnet-runtime Build product Log
495130 dotnet/runtime Build product Log dotnet/runtime#95797
2330640 dotnet-runtime Build product Log
484251 dotnet/runtime Build product Log dotnet/runtime#93989
482435 dotnet/runtime Build product Log dotnet/runtime#95337
481828 dotnet/runtime Build product Log dotnet/runtime#95249

Summary

24-Hour Hit Count 7-Day Hit Count 1-Month Count
0 1 6

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 31 (26 by maintainers)

Most upvoted comments

Mutex.Unix.cs is only used with the WaitSubsystem implementation, on CoreCLR the Unix implementation (confusingly) uses Mutex.Windows.cs, the p/invoke goes into the PAL, which implements Windows-like APIs such as ReleaseMutex.

@am11 I don’t think that would be it since that implementation does not support named mutexes.

I didn’t see anything obvious that would cause a ReleaseMutex to fail with ApplicationException. Another reason for throwing that exception is if the handle does not represent a mutex for some reason, though that would be unlikely.

Maybe it would be useful to add some more info to the exception message, like maybe:

  • Whether the mutex was created, and whether the mutex was abandoned in TryLock
  • The handle value seen after creation and before release
  • Include the exception stack trace in the message

Not sure it would help much but may at least rule something out.

Noticed something else, though it probably wouldn’t lead to this issue. This line should probably catch AbandonedMutexException and set IsLocked to true in that case, instead of catching it in the caller, otherwise IsLocked would remain false upon exception and the thread would abandon the mutex again.