Uploaded image for project: 'Apache Curator'
  1. Apache Curator
  2. CURATOR-347

Shared read/write lock acquired by one thread cannot be released by another

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.2.0
    • awaiting-response
    • Recipes
    • None

    Description

      Consider the following: lock is being acquired by main thread but released by another thread. This throws an exception:

      java.lang.IllegalMonitorStateException: You do not own the lock: /locks/abc
      at org.apache.curator.framework.recipes.locks.InterProcessMutex.release(InterProcessMutex.java:140)

      Are locks thread specific? That wouldn't make sense. How else can I achieve this? Also would be nice to have a non-reentrant read/write shared lock.

      public static void main(String[] args) throws Exception {
      final CuratorFramework client = CuratorFrameworkFactory.builder()
      .connectString(ApplicationProperties.getConfig().getMessagebusSyncServers()).sessionTimeoutMs(5000)
      .connectionTimeoutMs(3000).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build();
      client.start();
      InterProcessReadWriteLock lock = new InterProcessReadWriteLock(client, "/locks/abc");
      lock.writeLock().acquire();

      Thread r = new Thread() {

      @Override
      public void run() {
      try

      { InterProcessReadWriteLock lock = new InterProcessReadWriteLock(client, "/locks/abc"); lock.writeLock().release(); }

      catch (Exception e)

      { e.printStackTrace(); }

      }
      };
      r.start();
      r.join();
      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            meni Meni Hillel
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: