Repository navigation
Description
Description
In the following .NET versions, we have made the following changes to Named Mutex support in Unix.
The default scope for a named mutex on Unix is now user-scoped, instead of globally-scoped. Additionally, user-scoped mutexes now live in a system-defined user-only directory or a subdirectory of such a directory.
.NET Runtime 11.0-rc2
.NET Runtime 10.0.13
.NET Runtime 9.0.21
.NET Runtime 8.0.32
Version
Other (please put exact version in description textbox)
Previous behavior
Named mutexes on Unix platforms were globally-scoped across all users by default. User-scoped named mutexes were only definable with the System.Threading.Mutex constructors that take a System.Threading.NamedWaitHandleOptions parameter, available on .NET 10 or newer.
Additionally, user-scoped named mutexes are backed by files in a directory nested under /tmp/.
New behavior
Named mutexes on Unix platforms now default to user-scoped instead of globally-scoped. Globally scoped mutexes can be explicitly opted-into with the System.Threading.Mutex constructors that take a System.Threading.NamedWaitHandleOptions parameter on .NET 10 or newer, or by setting the System.Threading.Mutex.UnsafeDefaultMutexScopeGlobal runtime configuration option to true in your runtimeconfig.json for all affected platforms.
User-scoped mutexes are now stored under one of the following directories:
$TMPDIRwhen on a platform that defines$TMPDIRas a user-scoped directory.$XDG_RUNTIME_DIRwhen on a platform that conforms to the XDG Base Directory specification.$HOME/.dotnet/otherwise.
Type of breaking change
- Binary incompatible: Existing binaries might encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
- Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code might require source changes to compile successfully.
- Behavioral change: Existing binaries might behave differently at run time.
Reason for change
Due to security reasons, the default behavior needed to be adjusted to ensure that user-scoped mutexes are stored in user-owned locations. Additionally, for security reasons, the default was changed to ensure that usages across all versions of .NET default to a secure feature set by default.
Recommended action
If your named mutexes do not require cross-user access and your application can access the specified system directories for your platform, no changes are required.
If your named mutexes require cross-user access, you can opt into the unsafe global mutex behavior using the System.Threading.Mutex constructors that take a System.Threading.NamedWaitHandleOptions parameter on .NET 10 or newer, or by setting the System.Threading.Mutex.UnsafeDefaultMutexScopeGlobal runtime configuration option to true in your runtimeconfig.json for all affected platforms. Note that, per https://learn.microsoft.com/en-us/dotnet/api/system.threading.mutex?view=net-10.0#remarks, globally scoped mutexes are considered unsafe when used with multiple untrusted users on the same machine.
Feature area
Core .NET libraries
Affected APIs
All overloads of constructors for System.Threading.Mutex that take a string parameter.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields✅ Done
Activity
Adapt to dotnet/docs#56396 breaking change
Keep the exclusive DB lock machine-wide on .NET 10.0.13+
Keep the exclusive DB lock machine-wide on .NET 10.0.13+
7 remaining items
[DB-2257] Keep the exclusive DB lock machine-wide on .NET 10.0.13+ (#…
[DB-2257] Keep the exclusive DB lock machine-wide on .NET 10.0.13+ (#…
Adapt to dotnet/docs#56396 breaking change
[DB-2257] Keep the exclusive DB lock machine-wide on .NET 10.0.13+ (#…
[DB-2257] Keep the exclusive DB lock machine-wide on .NET 10.0.13+ (#…
[release/v26.2] [DB-2257] Keep the exclusive DB lock machine-wide on …
test(platform): preserve mutex backing root across Unix sessions
test(platform): preserve mutex backing root across Unix sessions