Skip to content

RedissonLock.tryLock() interrupted and keep renew lock #2714

Closed

Description

@fan0916

Expected behavior
when tryLock is interrupted, watchdog renew listener is cancelled too

Actual behavior
when tryLock is interrupted, watchdog keeps renewing lock, this makes ifinite lock

Steps to reproduce or test case
private volatile boolean threadTwoScheduled = false;
@test
public void lockThenInterruptNotCatchThenBroke() {
RLock lock = redissonClient.getLock("concurrent-test2");
Assert.assertFalse(lock.isLocked());

    Thread thread = new Thread(() -> {
        threadTwoScheduled = true;
        if (!lock.tryLock()) {
            return;
        }
        try {
            doBusiness();
        } finally {
            lock.unlock();
        }
    });
    thread.start();
    while(!threadTwoScheduled){}
    // let the tcp request be sent out
    for (int i = 0; i < 1000; i++) {
        new Object();
    }
    thread.interrupt();
    try {
        Thread.sleep(45000L); // longer than default watchdog time
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    // lock is still being renewed by watchdog
    Assert.assertTrue(lock.isLocked());
}

Redis version
doesn't matter
Redisson version
3.11.2
Redisson configuration

Activity

  1. added this to the 3.12.6 milestone on Apr 22, 2020
  2. modified the milestones: 3.13.0, 3.13.1 on May 22, 2020
  3. modified the milestones: 3.13.1, 3.13.2 on Jun 7, 2020
  4. modified the milestones: 3.13.2, 3.13.3 on Jul 3, 2020
  5. modified the milestones: 3.13.3, 3.13.4 on Aug 6, 2020
  6. modified the milestones: 3.13.4, 3.13.5 on Sep 4, 2020
  7. modified the milestones: 3.13.5, 3.13.6 on Sep 30, 2020
  8. modified the milestones: 3.13.6, 3.13.7 on Oct 14, 2020
  9. 10 remaining items

  10. modified the milestones: 3.15.3, 3.15.4 on Apr 1, 2021
  11. modified the milestones: 3.15.4, 3.15.5 on Apr 17, 2021
  12. modified the milestones: 3.15.6, 3.15.7 on May 13, 2021
  13. nomar22 commented on Jul 19, 2021

    @nomar22

    probably solved with #3714

  14. mrniko commented on Jul 19, 2021

    @mrniko
    Member

    @nomar22

    I'm afraid no. Still reproducible even with your fix

  15. modified the milestones: 3.16.1, 3.16.2 on Jul 26, 2021
  16. mrniko commented on Aug 6, 2021

    @mrniko
    Member

    This happens since watchdog works in Redisson instance scope not in thread.

  17. modified the milestones: 3.16.2, 3.16.3 on Sep 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions