Github user madrob commented on a diff in the pull request: https://github.com/apache/curator/pull/35#discussion_r16053998 --- Diff: curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutex.java --- @@ -107,4 +113,70 @@ public Void call() throws Exception client.close(); } } + + /** + * See CURATOR-79. If the mutex is interrupted while attempting to acquire a lock it is + * possible for the zNode to be created in ZooKeeper, but for Curator to think that it + * hasn't been. This causes the next call to acquire() to fail because the an orphaned + * zNode has been left behind from the previous call. + */ + @Test + public void testInterruptedDuringAcquire() throws Exception + { + Timing timing = new Timing(); + final CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); + client.start(); + final InterProcessMutex lock = new InterProcessMutex(client, LOCK_PATH); + + final AtomicBoolean interruptOnError = new AtomicBoolean(true); + + ((CuratorFrameworkImpl)client).debugUnhandledErrorListener = new UnhandledErrorListener() + { + + @Override + public void unhandledError(String message, Throwable e) + { + if(interruptOnError.compareAndSet(true, false)) + { + Thread.currentThread().interrupt(); + } + } + }; + + //The lock path needs to exist for the deadlock to occur. + try { + client.create().creatingParentsIfNeeded().forPath(LOCK_PATH); + } catch(NodeExistsException e) { + } + + try + { + //Interrupt the current thread. This will cause ensurePath() to fail. + //We need to reinterrupt in the debugUnhandledErrorListener above. + Thread.currentThread().interrupt(); + lock.acquire(); + Assert.fail(); --- End diff -- Can you add a message to the fail(), in case we see a regression in the future?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---