Merge pull request #2470 from StephanErb/zk-deadlock

Prevent deadlock in ZK TreeCache constructor by deferring the initial sync.
This commit is contained in:
Fabian Reinartz 2017-03-06 12:36:51 +01:00 committed by GitHub
commit 6aee1551e1
1 changed files with 7 additions and 7 deletions

View File

@ -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()
}