Skip to content

Commit

Permalink
The default watcher in the ZooKeeper handle is now cleared before the…
Browse files Browse the repository at this point in the history
… ZooKeeper handle is closed. This avoids

an edge case where events meant for the old ZooKeeper handle get processed.
  • Loading branch information
Randgalt committed Feb 6, 2013
1 parent ec18f3b commit 43021e4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -10,6 +10,9 @@ thanks to user barkbay for his persistence and help on this.
* Issue 245: Auth info specified in the CuratorFrameworkFactory.Builder was not being re-set in cases
where the internal ZooKeeper handle was recreated. i.e. if the cluster has issues auth info would be lost.

* The default watcher in the ZooKeeper handle is now cleared before the ZooKeeper handle is closed. This avoids
an edge case where events meant for the old ZooKeeper handle get processed.

1.3.1 - January 28, 2013
========================
* Tightened up a possible race deep inside the connection management.
Expand Down
Expand Up @@ -74,7 +74,7 @@ ZooKeeper getZooKeeper() throws Exception

if ( lost.compareAndSet(true, false) )
{
log.debug("resetting after loss");
log.info("resetting after loss");
reset();
}

Expand Down Expand Up @@ -157,7 +157,7 @@ void removeParentWatcher(Watcher watcher)

void markLost()
{
log.debug("lost");
log.info("lost marked");

lost.set(true);
}
Expand Down
Expand Up @@ -20,6 +20,7 @@

import com.netflix.curator.ensemble.EnsembleProvider;
import com.netflix.curator.utils.ZookeeperFactory;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

Expand Down Expand Up @@ -127,6 +128,14 @@ private void internalClose() throws Exception
ZooKeeper zooKeeper = (helper != null) ? helper.getZooKeeper() : null;
if ( zooKeeper != null )
{
Watcher dummyWatcher = new Watcher()
{
@Override
public void process(WatchedEvent event)
{
}
};
zooKeeper.register(dummyWatcher); // clear the default watcher so that no new events get processed by mistake
zooKeeper.close();
}
}
Expand Down

0 comments on commit 43021e4

Please sign in to comment.