dotnet / dotnet-api-docs

.NET API reference documentation (.NET 5+, .NET Core, .NET Framework)
https://docs.microsoft.com/dotnet/api/
Other
706 stars 1.55k forks source link

Docs should specify that names of Mutex, AutoResetEvent, and Semaphores may not contain '/' when running on Unix #8022

Open Whiletru3 opened 2 years ago

Whiletru3 commented 2 years ago

Description

I try to use System.Threading Mutex(bool initiallyOwned, string? name, out bool createdNew) on macOS in a net6 project. The name I use contain a slash ("/"). On windows I have no issue with it, but on macOS, I have an exception :

System.IO.IOException: The filename, directory name, or volume label syntax is incorrect. : '6dace8f3-282b-4b6e-ab0b-99026a8fb613/c8cf2963-3b12-4537-8a44-4aac2dad98dc'
   at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew)
   at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name, Boolean& createdNew)

There are no such of restriction in the documentation, only the backslash is reserved.

https://docs.microsoft.com/en-us/dotnet/api/system.threading.mutex?view=net-6.0

The backslash (\) is a reserved character in a mutex name. Don't use a backslash (\) in a mutex name except as specified in the note on using mutexes in terminal server sessions. Otherwise, a [DirectoryNotFoundException](https://docs.microsoft.com/en-us/dotnet/api/system.io.directorynotfoundexception?view=net-6.0) may be thrown, even though the name of the mutex represents an existing file.

It could be good to add the / as reserved.

Reproduction Steps

Mutex mutex = new Mutex(true, "1234/5678", out var isCreatedNew);

Expected behavior

no exception or invalid name

Actual behavior

launch an exception

Regression?

No response

Known Workarounds

replace / with another character

Configuration

.net6 Mac 12.3 x64

Other information

No response

ghost commented 2 years ago

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

Issue Details
### Description I try to use System.Threading Mutex(bool initiallyOwned, string? name, out bool createdNew) on macOS in a net6 project. The name I use contain a slash ("/"). On windows I have no issue with it, but on macOS, I have an exception : ``` System.IO.IOException: The filename, directory name, or volume label syntax is incorrect. : '6dace8f3-282b-4b6e-ab0b-99026a8fb613/c8cf2963-3b12-4537-8a44-4aac2dad98dc' at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew) at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name, Boolean& createdNew) ``` There are no such of restriction in the documentation, only the backslash is reserved. https://docs.microsoft.com/en-us/dotnet/api/system.threading.mutex?view=net-6.0 `The backslash (\) is a reserved character in a mutex name. Don't use a backslash (\) in a mutex name except as specified in the note on using mutexes in terminal server sessions. Otherwise, a [DirectoryNotFoundException](https://docs.microsoft.com/en-us/dotnet/api/system.io.directorynotfoundexception?view=net-6.0) may be thrown, even though the name of the mutex represents an existing file.` It could be good to add the / as reserved. ### Reproduction Steps Mutex mutex = new Mutex(true, "1234/5678", out var isCreatedNew); ### Expected behavior no exception or invalid name ### Actual behavior launch an exception ### Regression? _No response_ ### Known Workarounds replace / with another character ### Configuration .net6 Mac 12.3 x64 ### Other information _No response_
Author: Whiletru3
Assignees: -
Labels: `area-System.Threading`, `untriaged`
Milestone: -
danmoseley commented 2 years ago

Good catch. This is because on Unix, forward slash is not valid in a file name. Here's the check:

https://github.com/dotnet/runtime/blob/ad1dfb8890dd6baf6f8d2ad4b8c17f54b5bd3e66/src/coreclr/pal/src/sharedmemory/sharedmemory.cpp#L469-L477

Do you want to update the docs? As well as Mutex, EventWaitHandle and Semaphore also can be named and those names are subject to this restriction.

To update the docs, you can click the "edit" button (a pencil) at the top of the topic. Or provide a PR against the dotnet/dotnet-api-docs repo.

danmoseley commented 2 years ago

I'm going to move this issue to that repo, either way.