question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReadLock not working correctly

See original GitHub issue

Hi,

Is this the expected behaviour of the ReadLock from ReadWriteLock?

Clarifying because I did not encounter this in release 3.5.4

There are multiple threads that are trying to lock and unlock the readlock concurrently but I am encountering the “attempt to unlock lock, not locked by current thread by node id” exception.

Here is a rough code sample to replicate the issue.

ExecutorService service;
RReadWriteLock rwlock;
RLock rlock = rwlock.readLock();

for (int i=0; i<10; i++) {
  service.submit (() -> {
    for (int j=0; j<1000; j++) {
      rlock.lock();
      try {
      } finally {
         try {
           rlock.unlock();
         } catch(Exception e) {
            e.printStackTrace();
         }
      }
    }
  });
}

The unlock part throws the following exception even though they’re all read locks.

java.lang.IllegalMonitorStateException: attempt to unlock lock, not locked by current thread by node id: e3784ec0-94c6-4138-ac2a-1865eb79c93d thread-id: 21
	at org.redisson.RedissonLock.unlock(RedissonLock.java:367)
	at Main.lambda$0(Main.java:25)
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:36 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
chowtincommented, Nov 12, 2019

this error happens in 3.11.5. which version fixed this issue?

attempt to unlock lock, not locked by current thread by node id: e5dd1158-244f-43cc-a7ae-6bd34c62c783 thread-id: 70
0reactions
chowtincommented, Dec 17, 2019

@mrniko I changed async way to use redisson, also made waitLockTime > lockLeaseTime, this issue disappeared . this change has been put into production for several weeks, so i believe my usage was error, I/O thread was blocked somewhere.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FLUSH TABLES WITH READ LOCK not working?
I use this command to "lock" my database, flush logs , take a LVM snapshot and release it. Testing the recover + binlogs...
Read more >
Apache Camel - "Cannot acquire read lock" - Stack Overflow
I'm using Apache Camel version 2.24.2. I have two application servers that are polling a shared directory to pick up and process files....
Read more >
ReentrantReadWriteLock.ReadLock (Java Platform SE 7 )
Acquires the read lock if the write lock is not held by another thread within the given waiting time and the current thread...
Read more >
ReentrantReadWriteLock blocks obtaining read lock after ...
A ReentrantReadWriteLock with "FAIR" policy does not show this behaviour STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : - Create a ReentrantReadWriteLock ...
Read more >
SFTP readLock option - users@camel.apache.org
readLock =rename works, but just not sure in a cluster. Claus Ibsen. 10 years ago ... Assuming I read your question correctly, the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found