4

Closed

ArgumentException calling IndexWriter.IsLocked on directory which is not locked

description

Hello,

The following code in my project causes an ArgumentException to be thrown when checking IsLocked:
if (IndexWriter.IsLocked(_directory))
                {
                    IndexWriter.Unlock(_directory);
                }
The exception message is "A lease ID must be specified when releasing a lease".

My project is using
Lucene.Net.Store.Azure 2.0.4849.29611
Lucene.Net 3.0.3
WindowsAzure.Storage 2.0.5.1

I downloaded the code for Lucene and Lucene.Net.Store.Azure and stepped through it. The error occurs in the procedure below (from AzureLock.cs).
        override public bool IsLocked()
        {
            var blob = _azureDirectory.BlobContainer.GetBlobReferenceFromServer(_lockFile);
            try
            {
                Debug.Print("IsLockeD() : {0}", _leaseid);
                if (String.IsNullOrEmpty(_leaseid))
                {
                    var tempLease = blob.AcquireLease(TimeSpan.FromSeconds(60), _leaseid);
                    if (String.IsNullOrEmpty(tempLease))
                    {
                        Debug.Print("IsLocked() : TRUE");
                        return true;
                    }
                    blob.ReleaseLease(new AccessCondition() { LeaseId = _leaseid });
                }
                Debug.Print("IsLocked() : {0}", _leaseid);
                return String.IsNullOrEmpty(_leaseid);
            }
            catch (StorageException webErr)
            {
                if (_handleWebException(blob, webErr))
                    return IsLocked();
            }
            /*catch (StorageClientException err)
            {
                if (_handleStorageClientException(blob, err))
                    return IsLocked();
            }*/
            _leaseid = null;
            return false;
        }
If the directory is not locked, then _leaseid is null, so the code then attempts to acquire a temporary lease, which succeeds (tempLease has an id value). When ReleaseLease is called, _leaseId is used, which is null so an exception is thrown.

I believe that this portion of the code should be:
                Debug.Print("IsLocked() : {0}", _leaseid);
                if (String.IsNullOrEmpty(_leaseid))
                {
                    var tempLease = blob.AcquireLease(TimeSpan.FromSeconds(60), _leaseid);
                    if (String.IsNullOrEmpty(tempLease))
                    {
                        Debug.Print("IsLocked() : TRUE");
                        return true;
                    }
                    blob.ReleaseLease(new AccessCondition() { LeaseId =tempLease  });
                }
                Debug.Print("IsLocked() : {0}", tempLease );
                return String.IsNullOrEmpty(tempLease );
Closed May 8, 2013 at 11:49 PM by thermous
Thanks, fixed with release 2.0.4876.28221

comments

purplepangolin wrote May 9, 2013 at 7:03 AM

Excellent. Thanks for the prompt response.

wrote May 16, 2013 at 9:00 AM