Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hazelcast ILock coudln't release lock properly base on leasing time, if lock name contains "@" #12614

Closed
senwangrockets opened this issue Mar 15, 2018 · 5 comments

Comments

@senwangrockets
Copy link

@senwangrockets senwangrockets commented Mar 15, 2018

Tested on hazelcast java utility,

       <dependency>
		<groupId>com.hazelcast</groupId>
		<artifactId>hazelcast-client</artifactId>
		<version>3.9.1</version>
	</dependency>

Tested on code:

Thread t1 = new Thread(() -> {
  try {
    String abc = "someuser@something.com";
    ILock lock = hazelcastClientInstance.acquireLock(abc);
    System.out.println(lock.tryLock(0, TimeUnit.MILLISECONDS, 10, TimeUnit.SECONDS));
  } catch (InterruptedException e) {
    e.printStackTrace();
  }
});

Thread t2 = new Thread(() -> {
  try {
    String abc = "someuser@something.com";
    ILock lock = hazelcastClientInstance.acquireLock(abc);
    System.out.println(lock.tryLock(0, TimeUnit.MILLISECONDS, 10, TimeUnit.SECONDS));
  } catch (InterruptedException e) {
    e.printStackTrace();
  }
});

Thread t3 = new Thread(() -> {
  try {
    String abc = "someuser@something.com";
    ILock lock = hazelcastClientInstance.acquireLock(abc);
    System.out.println(lock.tryLock(0, TimeUnit.MILLISECONDS, 10, TimeUnit.SECONDS));
  } catch (InterruptedException e) {
    e.printStackTrace();
  }
});

t1.start();
t2.start();
Thread.sleep(11000);
t3.start();

Expected:
true,
false,
true.

But instead, got
true,
false,
false,

The lock never release after 10 seconds.

However if lock name is "someuser-something.com" instead of "someuser@something.com".

Everything works as expected.

@mdogan mdogan added the To Triage label Mar 16, 2018
@mdogan
Copy link
Contributor

@mdogan mdogan commented Mar 16, 2018

Your test looks timing sensitive. We cannot guarantee that 10 seconds lease will expire even after 11 seconds. We only guarantee that lease will remain at least 10 seconds. After 10 seconds it will eventually expire.

Following snippet shows lease expires with or without @ inside the lock name;

String name = "someuser@something.com";

Thread t = new Thread(() -> {
    ILock lock = hazelcastInstance.getLock(name);
    lock.lock(10, TimeUnit.SECONDS);
    System.out.println("1st thread acquired the lock.");
});
t.start();
t.join();

ILock lock = hazelcastInstance.getLock(name);
lock.lock();
System.out.println("2nd thread acquired the lock.");
@senwangrockets
Copy link
Author

@senwangrockets senwangrockets commented Mar 16, 2018

Thanks @mdogan .

I tried on my setup, use the same snippet you providered, the one with '@' hangs forever. Without '@' works fine. May I ask what version of hazelcast you are using?

I'm testing on setup, hazelcast-server on kubernetes, java code locally and hazelcast instance configured as a hazelcast client.

@senwangrockets
Copy link
Author

@senwangrockets senwangrockets commented Mar 16, 2018

By the way, if I switch back to the old hazlecast version, it will works. Last working one I can use is

	<dependency>
		<groupId>com.hazelcast</groupId>
		<artifactId>hazelcast-client</artifactId>
		<version>3.6.8</version>
	</dependency>
@mdogan
Copy link
Contributor

@mdogan mdogan commented Mar 19, 2018

@senwangrockets: My bad. I was not using hazelcast-client, but testing directly with server. With client, I can reproduce it with latest master too.

@senwangrockets
Copy link
Author

@senwangrockets senwangrockets commented Mar 19, 2018

Cool, thanks very much, keep me updated, for now, I'll use the old version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.