From fad99a3f68577c7702d104de332545ab188ccaed Mon Sep 17 00:00:00 2001 From: tedyu Date: Tue, 7 Jun 2016 09:14:01 -0700 Subject: [PATCH] HBASE-15803 ZooKeeperWatcher's constructor can leak a ZooKeeper instance with throwing ZooKeeperConnectionException when canCreateBaseZNode is true --- .../hadoop/hbase/zookeeper/ZooKeeperWatcher.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java index e6c8eb914c0..3b0c2b68f58 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java @@ -181,7 +181,17 @@ public class ZooKeeperWatcher implements Watcher, Abortable, Closeable { this.recoverableZooKeeper = ZKUtil.connect(conf, quorum, pendingWatcher, identifier); pendingWatcher.prepare(this); if (canCreateBaseZNode) { - createBaseZNodes(); + try { + createBaseZNodes(); + } catch (ZooKeeperConnectionException zce) { + try { + this.recoverableZooKeeper.close(); + } catch (InterruptedException ie) { + LOG.debug("Encountered InterruptedException when closing " + this.recoverableZooKeeper); + Thread.currentThread().interrupt(); + } + throw zce; + } } }