From 3038d0eb9b0d37ef560635bcbbe2a2d9cdab86fa Mon Sep 17 00:00:00 2001 From: Stephan Erb Date: Fri, 3 Mar 2017 23:51:13 +0100 Subject: [PATCH] Prevent deadlock in ZK TreeCache constructor by deferring the initial sync. Fixes #2254 --- util/treecache/treecache.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/util/treecache/treecache.go b/util/treecache/treecache.go index 3e9691f34..6f0e213b1 100644 --- a/util/treecache/treecache.go +++ b/util/treecache/treecache.go @@ -86,11 +86,7 @@ func NewZookeeperTreeCache(conn *zk.Conn, path string, events chan ZookeeperTree children: map[string]*zookeeperTreeCacheNode{}, stopped: true, } - err := tc.recursiveNodeUpdate(path, tc.head) - if err != nil { - log.Errorf("Error during initial read of Zookeeper: %s", err) - } - go tc.loop(err != nil) + go tc.loop(path) return tc } @@ -98,7 +94,8 @@ func (tc *ZookeeperTreeCache) Stop() { tc.stop <- struct{}{} } -func (tc *ZookeeperTreeCache) loop(failureMode bool) { +func (tc *ZookeeperTreeCache) loop(path string) { + failureMode := false retryChan := make(chan struct{}) failure := func() { @@ -108,7 +105,10 @@ func (tc *ZookeeperTreeCache) loop(failureMode bool) { retryChan <- struct{}{} }) } - if failureMode { + + err := tc.recursiveNodeUpdate(path, tc.head) + if err != nil { + log.Errorf("Error during initial read of Zookeeper: %s", err) failure() }