GunnerMBT / csharptest-net

Automatically exported from code.google.com/p/csharptest-net
0 stars 0 forks source link

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

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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;
}

Original issue reported on code.google.com by Frame...@gmail.com on 28 May 2014 at 1:23

GoogleCodeExporter commented 8 years ago
Issue moved:
https://github.com/csharptest/CSharpTest.Net.Collections/issues/7

Original comment by Grig...@gmail.com on 29 Jan 2015 at 5:47