[ https://issues.apache.org/jira/browse/CURATOR-507?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16772386#comment-16772386 ]
Cameron McKenzie commented on CURATOR-507: ------------------------------------------ I don't think it's a race condition. The two paths for initialisationComplete() to be called seem mutually exclusive to me, but maybe I'm missing something. Could you write a small unit test to reproduce the problem? It's difficult to work out what's going on from the code snippets. > PERSISTENT NODE ISSUE > --------------------- > > Key: CURATOR-507 > URL: https://issues.apache.org/jira/browse/CURATOR-507 > Project: Apache Curator > Issue Type: Bug > Components: Recipes > Affects Versions: 4.1.0 > Reporter: Evaristo > Priority: Major > > Hi there, > I am using Apache Curator 4.1.0 with Zk 3.4.10 (Open JDK 1.8) > openjdk version "1.8.0_191" > I am PersistentNode recipe and I am receiving this exception > > java.lang.IllegalStateException: initial create has not been processed. Call > waitForInitialCreate() to ensure. > at > org.apache.curator.shaded.com.google.common.base.Preconditions.checkState(Preconditions.java:444) > at > org.apache.curator.framework.recipes.nodes.PersistentNode.setData(PersistentNode.java:392) > at com.cheva.udr.sm.RemoteReporter.reportToRemote(RemoteReporter.java:67) > at com.cheva.udr.sm.RemoteReporter.lambda$2(RemoteReporter.java:84) > at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) > at java.util.concurrent.FutureTask.run(FutureTask.java:266) > at > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) > at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) > at java.lang.Thread.run(Thread.java:748) > > My class RemoteReporter.java (assumes that PersistentNode is thread safe) > // The class is final, and the attribute is private final so allow safe > publication > private final Persistent pn; > Constrcutor() { > ... > PersistentNode pn = new PersistentNode(cf, CreateMode.EPHEMERAL, false, path, > dataToReport()); > } > // Class has also an start method > start() { > ... > 79 pn.start(); > ... > // Create new thread and execute the follwoing code > 84 pn.waitForInitialCreate(1000, TimeUnit.DAYS); > 85 pn.setData("XXx"); > 86 statusCache.getListenable().addListener(listener); > } > I was checking the PersistentNode code and the excepction happens because > nodePath.get()==null variable. I am not 100% sure if the problem is in my > code or in the recipe... > - My code is using the waitForinitial as suggested > - The recipe uses a CountDownLatch, but there are 2 different paths for the > latch to be countDown (via initalisationComplete() method), and I am not sure > that one of them assures that nodePath.get() != null > In this code snippet, you can see that the latch is countDown, but I am not > sure that nodePath.set(whatever) is called, so I guess there could be a race > condition > private final BackgroundCallback setDataCallback = new BackgroundCallback() > { > @Override > public void processResult(CuratorFramework dummy, CuratorEvent event) > throws Exception > { > //If the result is ok then initialisation is complete (if we're still > initialising) > //Don't retry on other errors as the only recoverable cases will be > connection loss > //and the node not existing, both of which are already handled by other > watches. > if ( event.getResultCode() == KeeperException.Code.OK.intValue() ) > { > //Update is ok, mark initialisation as complete if required. > initialisationComplete(); > } > else if ( event.getResultCode() == KeeperException.Code.NOAUTH.intValue() ) > { > log.warn("Client does not have authorisation to write node at path {}", > event.getPath()); > authFailure.set(true); > } > } > }; > Thanks in adavance for the help, > Evaristo > -- This message was sent by Atlassian JIRA (v7.6.3#76005)