CSharpTest.Net.Collections icon indicating copy to clipboard operation
CSharpTest.Net.Collections copied to clipboard

BPlusTree: CallLevel lock is never released in the case of exception

Open csharptest opened this issue 10 years ago • 1 comments

There is a possibility that CallLevel lock would never be released. And this is really happening if LockTimeout expires in NodeCache.

Here is the code in the constructor of RootLock:

_locked = _exclusive ? _tree._selfLock.TryWrite(tree._options.LockTimeout) : _tree._selfLock.TryRead(tree._options.LockTimeout);
Assert(_locked);
Pin = _tree._storage.LockRoot(type);

If an exception is thrown in '_tree._storage.LockRoot(type)' then '_tree._selfLock' will never be released. So the code should be enclosed by try..catch:

try
{
    Pin = _tree._storage.LockRoot(type);
}
catch
{
    if (_exclusive)
       _tree._selfLock.ReleaseWrite();
    else
       _tree._selfLock.ReleaseRead();
    throw;
}

csharptest avatar Jan 29 '15 17:01 csharptest

Fixed on /dev

csharptest avatar Feb 23 '15 00:02 csharptest