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

Get Sharing violation exception #56

Open
jessejiang0214 opened this issue Mar 5, 2019 · 6 comments
Open

Get Sharing violation exception #56

jessejiang0214 opened this issue Mar 5, 2019 · 6 comments

Comments

@jessejiang0214
Copy link

Hi James,
I used MonkeyChache.FileStore 1.2.0-beta in my .NetStandard 2.0 Xamarin.forms project.

I got this exception when I try to call

 Barrel.Current.Exists(key);
System.IO.IOException: Sharing violation on path /data/user/0/com.xx.app/MonkeyCacheFS/idx.dat

Do you have any idea why it throw this exceptions?
I can catch the exception and it works fine. Do you think it's necessary to mention this in the document?

Thanks,
Jesse

@jamesmontemagno
Copy link
Owner

I would need a repro as this doesn't touch the files at all so that would be odd.

@ssm3ll
Copy link

ssm3ll commented Oct 14, 2019

@jessejiang0214 just check your code it doesn't access file at the same time from different threads

@JMan7777
Copy link

JMan7777 commented Jan 13, 2020

Hi,

I'm having the same issue on MonkeyCache.FileStore.
I just moved from MonkeyCache.LiteDB to MonkeyCache.FileStore since I had performance issues if the cache was getting too big.

In MonkeyCache.LiteDB I never encountered any concurrent access problems from different threads
but now I'm also getting the Sharing violation (without changing anything else in my code).

@jamesmontemagno Could you please modify MonkeyCache.FileStore to ensure that only one process accessing the underlying file at the same time.

Since my code is highly multi threaded I need to use a wrapper around MonkeyCache.FileStore accesses at the moment to ensure single access.

`public sealed class CustomBarrel : IBarrel
{
private CustomBarrel()
{
}

    private static readonly object padlock = new object();

    private static readonly Lazy<CustomBarrel> lazy = new Lazy<CustomBarrel>(() => new CustomBarrel());

    public static string ApplicationId
    {
        get { return Barrel.ApplicationId; }
        set { Barrel.ApplicationId = value; }
    }

    public static CustomBarrel Current
    {
        get
        {
            return lazy.Value;
        }
    }

    public void Add<T>(string key, T data, TimeSpan expireIn, string eTag = null, JsonSerializerSettings jsonSerializationSettings = null)
    {
        lock (padlock)
        {
            Barrel.Current.Add(key, data, expireIn, eTag, jsonSerializationSettings);
        }
    }

    public void Empty(params string[] key)
    {
        lock (padlock)
        {
            Barrel.Current.Empty(key);
        }
    }

    public void EmptyAll()
    {
        lock (padlock)
        {
            Barrel.Current.EmptyAll();
        }
    }

    public void EmptyExpired()
    {
        lock (padlock)
        {
            Barrel.Current.EmptyExpired();
        }
    }

    public bool Exists(string key)
    {
        lock (padlock)
        {
            return Barrel.Current.Exists(key);
        }
    }

    public T Get<T>(string key, JsonSerializerSettings jsonSettings = null)
    {
        lock (padlock)
        {
            return Barrel.Current.Get<T>(key, jsonSettings);
        }
    }

    public string GetETag(string key)
    {
        lock (padlock)
        {
            return Barrel.Current.GetETag(key);
        }
    }

    public DateTime? GetExpiration(string key)
    {
        lock (padlock)
        {
            return Barrel.Current.GetExpiration(key);
        }
    }

    public IEnumerable<string> GetKeys(CacheState state = CacheState.Active)
    {
        lock (padlock)
        {
            return Barrel.Current.GetKeys(state);
        }
    }

    public bool IsExpired(string key)
    {
        lock (padlock)
        {
            return Barrel.Current.IsExpired(key);
        }
    }
}`

But I think such mechanism should be in MonkeyCache.FileStore itself.

Thx a lot.

Markus

@ilyalehchylin
Copy link

ilyalehchylin commented Apr 2, 2020

Getting this exception in the following way (not always):

  1. App crashes for any reason (not related to MonkeyCache)
  2. Starting the app again
  3. Crash with System.IO.IOException: Sharing violation on path /data/user/0/com.xx.app/MonkeyCacheFS/idx.dat message.

Note: on app start I call networking services and save the responses with MonkeyCache.

@mos379
Copy link

mos379 commented Oct 24, 2020

@jamesmontemagno do you think it would be possible to enhance MonkeyCache to prevent this multithreading problem?

@vynxc
Copy link

vynxc commented Dec 6, 2022

also happening to me

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

No branches or pull requests

7 participants