-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Changes to properly support Mutexes on NET6.0 #2206
base: master
Are you sure you want to change the base?
Changes to properly support Mutexes on NET6.0 #2206
Conversation
Global Mutexes were being created without insufficient rights for a 2nd process running on same machine to use them
Is there any plan on merging this PR? |
Any update? What's the symptom without this fix, is there a particular error raised? Looking for solutions to access denied errors on shared mode access, but I'm not seeing it on the mutex but on the journal file (and only one process is writing, the other opens database in read mode). |
I would also like to see some repro code before merging this. |
@JKamsker I can't provide a repro, but I can provide the scenario. Environment: Windows 10/11 2 writer processes from different users. This happened sometimes during our tests, but our customers encountered it all the time, forcing us to release a patch disabling some functionalities. |
@inbarbarkai Oh i remember now, i had a similar problem with named pipes and different users. Ok thank you for the clarification! I will try to get to it asap :) |
Similar to above, have not reproduced the issues we see, but have had them from customers, particularly this kind of error.
This occurs either on .db or the log, and the processes all open the database in shared mode. Have tried long and short lived instances of LiteDatabase also (I believe in shared mode it is internally opening and closing connections on each operation so likely makes little difference, unlike direct mode). Could this occur if the mutexes aren't being acquired right? Though would you see a mutex error instead? Or is there a potential race condition somewhere? We've done extensive diagnostics and cannot see what the other process is. Some customers show signs of things like Microsoft Defender for Endpoints (the corporate version of Defender) access files but looks more like it detecting file access not actually opening and locking files. Other customers don't have anything like this though. Any solution needs to be proven fix to roll out to customers though as already got frustrated customers, hence repo is very desirable. Only alternative have thought about is to move to a single process for database operations and some communication between them. Getting into building a database server territory though and already considering supporting MongoDB as an alternative to LiteDB. |
LiteDB/Client/Shared/SharedEngine.cs
Outdated
#if NETFRAMEWORK || NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER | ||
#if NET6_0_OR_GREATER | ||
if (!OperatingSystem.IsWindows()) | ||
_mutex = new Mutex(false, "Global\\" + name + ".Mutex"); | ||
else | ||
{ | ||
#endif | ||
var allowEveryoneRule = new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), | ||
MutexRights.FullControl, AccessControlType.Allow); | ||
|
||
var securitySettings = new MutexSecurity(); | ||
securitySettings.AddAccessRule(allowEveryoneRule); | ||
|
||
var securitySettings = new MutexSecurity(); | ||
securitySettings.AddAccessRule(allowEveryoneRule); | ||
#if NET6_0_OR_GREATER | ||
_mutex = MutexAcl.Create(false, "Global\\" + name + ".Mutex", out _, securitySettings); | ||
#endif | ||
#if NETFRAMEWORK | ||
_mutex = new Mutex(false, "Global\\" + name + ".Mutex", out _, securitySettings); | ||
#endif | ||
#if NETSTANDARD2_0_OR_GREATER | ||
_mutex = new Mutex(false, "Global\\" + name + ".Mutex"); | ||
ThreadingAclExtensions.SetAccessControl(_mutex, securitySettings); | ||
#endif | ||
#else | ||
_mutex = new Mutex(false, "Global\\" + name + ".Mutex"); | ||
#endif | ||
#if NET6_0_OR_GREATER | ||
} | ||
#endif | ||
} | ||
catch (NotSupportedException ex) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big nope! Please make it more readable.
LiteDB/LiteDB.csproj
Outdated
<AssemblyVersion>5.0.12</AssemblyVersion> | ||
<FileVersion>5.0.12</FileVersion> | ||
<VersionPrefix>5.0.12</VersionPrefix> | ||
<TargetFrameworks>netstandard1.3;netstandard2.0;net6.0</TargetFrameworks> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not going to add or drop support for any TargetFrameworks just yet ;)
I am not sure about the added dependencies. What do you think @pictos |
Hi all - Is there any update regarding following the Microsoft support matrix? I'd love to add .NET 8 support if that's allowed. I was able to get this working locally for my .NET 8 applications using the code from this related issue, but I would be happy to help get this merged if I can. |
Global Mutexes were being created without insufficient rights for a 2nd process running on same machine to use them
This fix addresses that by using same methodology applied to NETFRAMEWORK but to NET6.0