-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Named mutex not working on Linux and MacOS when AOT compiling #110348
Comments
Tagging subscribers to this area: @mangod9 |
I think this is #48720. Native AOT uses the managed Mutex implementation, not the one in CoreCLR PAL. |
What's the state of this issue? Just tried .net 9 and Mutex still doesn't work as expected if compiled with AOT. |
The implementation used by NativeAOT currently just uses in-process mutexes and doesn't support cross-process synchronization. Fixing that would be good and is under consideration. If you're using a named mutex to limit an application to one instance, an alternative may be to use the file system. Does your scenario need some of the other functionality of mutexes? |
The issue with using the file system is that if the application crashes, it can lead to a deadlock until the user manually deletes the file... |
@scgm0 this works for me on Linux, Mac and Windows: try
{
_lockFile = File.Open(LockFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
}
catch (Exception e)
{
Log.Information("Another Instance is already Running");
Environment.Exit(1);
} If the application crashes and the lockfile doesn't get removed, the exclusive lock can be acquired on restart. |
Thanks for the approach! I'll see if it's available later |
Description
Acquiring a global named mutex doesn't seem to work on MacOS and Linux when the application is compiled with NativeAOT.
Reproduction Steps
Compile to native using the following:
Expected behavior
The second instance of the program blocks and waits until the first has terminated
Actual behavior
The second instance successfully acquires the mutex.
Regression?
No response
Known Workarounds
No response
Configuration
Other information
The same works if the application is not compiled to native code but simply build in release mode:
The text was updated successfully, but these errors were encountered: