Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-5738

NativeLock is release if Lock is closed after obtain failed

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 4.8.1
    • 4.9, 6.0
    • None
    • None
    • New

    Description

      if you obtain the NativeFSLock and try to obtain it again in the same JVM and close if if it fails another process will be able to obtain it. This is pretty trappy though. If you execute the main class twice the problem becomes pretty obvious.

      import org.apache.lucene.store.Lock;
      import org.apache.lucene.store.NativeFSLockFactory;
      
      import java.io.File;
      import java.io.IOException;
      
      public class TestLock {
       public static void main(String[] foo) throws IOException, InterruptedException {
              NativeFSLockFactory lockFactory = new NativeFSLockFactory(new File("/tmp"));
              Lock lock = lockFactory.makeLock("LOCK");
              if (lock.obtain()) {
                  System.out.println("OBTAINED");
              } else {
                  lock.close();
                  System.out.println("FAILED");
              }
              // try it again and close it if it fails
              lock = lockFactory.makeLock("LOCK"); // <<<<==== this is a new lock
              if (lock.obtain()) {
                  System.out.println("OBTAINED AGAIN");
              } else {
                  lock.close(); // <<<<==== this releases the lock we obtained
                  System.out.println("FAILED on Second");
              }
              Thread.sleep(Integer.MAX_VALUE);
          }
      }
      
      

      Attachments

        1. LUCENE-5738.patch
          9 kB
          Simon Willnauer
        2. LUCENE-5738.patch
          8 kB
          Simon Willnauer

        Activity

          People

            simonw Simon Willnauer
            simonw Simon Willnauer
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: