dotnetcore / EasyCaching

:boom: EasyCaching is an open source caching library that contains basic usages and some advanced usages of caching which can help us to handle caching more easier!
MIT License
1.92k stars 324 forks source link

System.ObjectDisposedException: Cannot access a disposed object 'System.Threading.SemaphoreSlim' #525

Open albertwoo opened 4 months ago

albertwoo commented 4 months ago

Description

I cannot always reproduce this, but this happens in my concurrent test code and my business code is using MemoryLockFactory from EasyCaching.Core.

System.ObjectDisposedException: Cannot access a disposed object.
  Object name: 'System.Threading.SemaphoreSlim'.
     at System.Threading.SemaphoreSlim.WaitAsync(Int32 millisecondsTimeout, CancellationToken cancellationToken)
     at EasyCaching.Core.DistributedLock.MemoryLock.LockAsync(Int32 millisecondsTimeout, CancellationToken cancellationToken)

Related code

try {
    if (await distributedLock.LockAsync(3000)) {
       ...
    }
    else {
        throw new Exception("xxx");
    }
}
finally {
    await distributedLock.ReleaseAsync();
}

Specifications

catcherwong commented 4 months ago

@albertwoo Thanks for your interest in this project.

We will take a look ASAP.