Skip to content
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

[BUG] "Access to the path 'xxx.Mutex' is denied ." is still present. #1707

Open
eschlot opened this issue Jun 4, 2020 · 4 comments
Open
Labels

Comments

@eschlot
Copy link

eschlot commented Jun 4, 2020

Version
LiteDB 5.0.8 on Windows 10 .NETCore.UniversalWindowsPlatfrom v6.2.10

Describe the bug
Connection String "Connection=Shared" creates an

System.UnauthorizedAccessException: "Access to the path 'Global\B6D440A8AE428F3AA71B8602C73A7D4BE8C92A7A.Mutex' is denied."

The same code runs without problems in case of direct mode. But this causes problem with my design in other places.

Code to Reproduce

Note: The access to the LiteDB is performed within the instantiation of the MainModel class.

public class MainModel
{
  public readonly static string dbFile = @"Filename="+Windows.Storage.ApplicationData.Current.RoamingFolder.Path + @"\db.litedb.txt;Connection=shared";
  public readonly static ConnectionString connectionString = new ConnectionString(dbFile);
  readonly BasicSetting _visibleItem = new BasicSetting("VisibleItem", `string.Empty);

}

class BasicSetting
{

    public class BasicInnerSetting
    {
        public int Id { get; set; } // For liteDB
        public string Key { get; set; }
        public string Value { get; set; }
    }

    public BasicSetting(string key, string defaultValue)
    {
        this._key = key;
        using (LiteDatabase db = new LiteDatabase(MainModel.connectionString))
        {
            var basicSetting = db.GetCollection<BasicInnerSetting>("basicsetting");
            BasicInnerSetting result = basicSetting.FindOne(Query.EQ("Key",key));
            
            if (result==null)
            {
                this._value = defaultValue;
                BasicInnerSetting bis = new BasicInnerSetting
                {
                    Key = key,
                    Value = defaultValue
                };
                basicSetting.Insert(bis);
            }
            else
            {
                this._value = result.Value;
            }
        }
    }

The problem occurs on the line where the using expression is initiated.

I cannot say if this problem also exists in case the code is used outside of my application. Only tested this within my complete application.

Expected behavior
Expectation is that the mutex is working. There is no reason (to my knowledge) why this should not work.

Screenshots/Stacktrace
System.UnauthorizedAccessException
HResult=0x80070005
Nachricht = Access to the path 'Global\B6D440A8AE428F3AA71B8602C73A7D4BE8C92A7A.Mutex' is denied.
Quelle = System.Private.CoreLib
Stapelüberwachung:
at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew)
at LiteDB.SharedEngine..ctor(EngineSettings settings)
at LiteDB.ConnectionString.CreateEngine()
at LiteDB.LiteDatabase..ctor(ConnectionString connectionString, BsonMapper mapper)
at ImageBrowser2.BasicSetting..ctor(String key, String defaultValue) in C:\data\development\Windows\ImageBrowser2\ImageBrowser2\BasicSetting.cs:line 23
at ImageBrowser2.MainModel..ctor() in C:\data\development\Windows\ImageBrowser2\ImageBrowser2\MainModel.cs:line 33
at ImageBrowser2.App.RestoreState() in C:\data\development\Windows\ImageBrowser2\ImageBrowser2\App.xaml.cs:line 108
at ImageBrowser2.App.OnLaunched(LaunchActivatedEventArgs e) in C:\data\development\Windows\ImageBrowser2\ImageBrowser2\App.xaml.cs:line 66

Diese Ausnahme wurde ursprünglich von dieser Aufrufliste ausgelöst:
[Externer Code]
ImageBrowser2.BasicSetting.BasicSetting(string, string) in BasicSetting.cs
ImageBrowser2.MainModel.MainModel() in MainModel.cs
ImageBrowser2.App.RestoreState() in App.xaml.cs
ImageBrowser2.App.OnLaunched(Windows.ApplicationModel.Activation.LaunchActivatedEventArgs) in App.xaml.cs

Additional context
The design of my application was always to use a shared access only. This was working fine with LiteDBv4. LiteDB v5 seems to have several issues with shared access, still.

@eschlot eschlot added the bug label Jun 4, 2020
@lbnascimento
Copy link
Collaborator

@eschlot The way we resolved this issue requires MutexAccessRule, which is only available in our .NET Framework target (even though .NET Core supports it, we don't target it directly, we target .NET Standard, which does not support it). I'm not sure what could be done, other than completely reworking the Shared mode (which is being done already).

@eschlot
Copy link
Author

eschlot commented Jun 4, 2020

Hello Leonardo,

thank You for the information.
I would suggest to document that the current shared mode is not functional in .NETCore. That could help people to identify the problem early.
Any idea when the rework of the shared mode will be available?

@tjmoore
Copy link

tjmoore commented Feb 2, 2021

Have users hit this error but unsure if it's an environment issue, how I'm using LiteDB or something else.

Also have hit a similar or maybe the same issue on Linux, raised under #1918. In that case a restart of the process (running as a service) seemed to fix it. The issue here however seems to be on start up, and immediately hits this, but am trying to get further detail on the environment (e.g. in case of a dormant process, although I expect shared mode to not have a problem with multiple processes).

How is the mutex shared between instances by the way? It must be stored somewhere for each instance to pick up. Is the name value unique and permanent for the database, or can it change?

Fall back to v4 is not really an option, nor is not using shared mode.

@haiduong87
Copy link

haiduong87 commented Apr 29, 2021

@eschlot The way we resolved this issue requires MutexAccessRule, which is only available in our .NET Framework target (even though .NET Core supports it, we don't target it directly, we target .NET Standard, which does not support it). I'm not sure what could be done, other than completely reworking the Shared mode (which is being done already).

Hi @lbnascimento

Can you consider to support MutexAccessRule , by using this package https://www.nuget.org/packages/System.Threading.AccessControl/6.0.0-preview.3.21201.4

_mutex.SetAccessControl(securitySettings);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants