You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@curator.apache.org by "Orcun Simsek (JIRA)" <ji...@apache.org> on 2014/08/05 20:44:12 UTC

[jira] [Comment Edited] (CURATOR-79) InterProcessMutex doesn't clean up after interrupt

    [ https://issues.apache.org/jira/browse/CURATOR-79?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13833414#comment-13833414 ] 

Orcun Simsek edited comment on CURATOR-79 at 8/5/14 6:43 PM:
-------------------------------------------------------------

Also adding a test that fails. (slight modification of the test attached in the original thread)
{code:title=Test.java|borderStyle=solid}
@Test
    public void testInterruptDeadlock() throws Exception {
        CuratorFramework client = CuratorFrameworkFactory.builder()
            .connectString("127.0.0.1:2181")
            .retryPolicy(new RetryNTimes(10, 1000))
            .build();
        client.start();

        Thread.currentThread().interrupt();
        final InterProcessMutex lock = new InterProcessMutex(client, "/testInterruption4");
        try {
            try {
                lock.acquire();
                lock.release();
            } catch (InterruptedException e) {
                if (lock.isAcquiredInThisProcess()) {
                    lock.release();
                }
            }
            assertTrue(lock.acquire(10, TimeUnit.MILLISECONDS));
        } finally {
            if (lock.isAcquiredInThisProcess()) {
                System.out.println("Lock released successfully.");
                lock.release();
            }
        }
    }
{code}



was (Author: ortschun):
Also adding a test that fails. (slight modification of the test attached in the original thread)
{code:title=Test.java|borderStyle=solid}
@Test
public void testInterruptDeadlock() throws Exception {
    CuratorFramework client = CuratorFrameworkFactory.builder()
        .connectString("127.0.0.1:2181")
        .retryPolicy(new RetryNTimes(10, 1000))
        .build();
    client.start();

    Thread.currentThread().interrupt();
    final InterProcessMutex lock = new InterProcessMutex(client, "/testInterruption");

    try {
        lock.acquire();
        lock.release();
     } catch (InterruptedException e) {
        if (lock.isAcquiredInThisProcess()) {
            lock.release();
        }
    }

    assertTrue(lock.acquire(10, TimeUnit.MILLISECONDS));
}
{code}

The exception:

{code}
java.lang.InterruptedException
	at java.lang.Object.wait(Native Method)
	at java.lang.Object.wait(Object.java:503)
	at org.apache.zookeeper.ClientCnxn.submitRequest(ClientCnxn.java:1309)
	at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:781)
	at com.netflix.curator.framework.imps.CreateBuilderImpl$10.call(CreateBuilderImpl.java:625)
	at com.netflix.curator.framework.imps.CreateBuilderImpl$10.call(CreateBuilderImpl.java:609)
	at com.netflix.curator.RetryLoop.callWithRetry(RetryLoop.java:106)
	at com.netflix.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:605)
	at com.netflix.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:428)
	at com.netflix.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:408)
	at com.netflix.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:41)
	at com.netflix.curator.framework.recipes.locks.LockInternals.attemptLock(LockInternals.java:222)
	at com.netflix.curator.framework.recipes.locks.InterProcessMutex.internalLock(InterProcessMutex.java:218)
	at com.netflix.curator.framework.recipes.locks.InterProcessMutex.acquire(InterProcessMutex.java:74)
{code}

> InterProcessMutex doesn't clean up after interrupt
> --------------------------------------------------
>
>                 Key: CURATOR-79
>                 URL: https://issues.apache.org/jira/browse/CURATOR-79
>             Project: Apache Curator
>          Issue Type: Bug
>    Affects Versions: 2.0.0-incubating, 2.1.0-incubating, 2.2.0-incubating, 2.3.0
>            Reporter: Orcun Simsek
>            Assignee: Jordan Zimmerman
>
> InterProcessMutex can deadlock if a thread is interrupted during acquire().  Specifically, CreateBuilderImpl.pathInForeground submits a create request to ZooKeeper, and an InterruptedException is thrown after the node is created in ZK but before ZK.create returns. ZK.create propagates a non-KeeperException, so Curator assumes the create has failed, but does not retry, and the node is now orphaned. At some point in the future, the node becomes the next in the acquisition sequence, but is not reclaimed as the ZK session has not expired.
> <stack trace attached in comments below>
> Curator should catch the InterruptedException and other non-KeeperExceptions, and delete the created node before propagating these exceptions.
> (as originally discussed on https://groups.google.com/forum/#!topic/curator-users/9ii5of8SbdQ)



--
This message was sent by Atlassian JIRA
(v6.2#6252)