mirror of
https://github.com/prometheus/prometheus
synced 2024-12-26 00:23:18 +00:00
Prevent deadlock in ZK TreeCache constructor by deferring the initial sync.
Fixes #2254
This commit is contained in:
parent
0a7fb56b16
commit
3038d0eb9b
@ -86,11 +86,7 @@ func NewZookeeperTreeCache(conn *zk.Conn, path string, events chan ZookeeperTree
|
|||||||
children: map[string]*zookeeperTreeCacheNode{},
|
children: map[string]*zookeeperTreeCacheNode{},
|
||||||
stopped: true,
|
stopped: true,
|
||||||
}
|
}
|
||||||
err := tc.recursiveNodeUpdate(path, tc.head)
|
go tc.loop(path)
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Error during initial read of Zookeeper: %s", err)
|
|
||||||
}
|
|
||||||
go tc.loop(err != nil)
|
|
||||||
return tc
|
return tc
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +94,8 @@ func (tc *ZookeeperTreeCache) Stop() {
|
|||||||
tc.stop <- struct{}{}
|
tc.stop <- struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tc *ZookeeperTreeCache) loop(failureMode bool) {
|
func (tc *ZookeeperTreeCache) loop(path string) {
|
||||||
|
failureMode := false
|
||||||
retryChan := make(chan struct{})
|
retryChan := make(chan struct{})
|
||||||
|
|
||||||
failure := func() {
|
failure := func() {
|
||||||
@ -108,7 +105,10 @@ func (tc *ZookeeperTreeCache) loop(failureMode bool) {
|
|||||||
retryChan <- struct{}{}
|
retryChan <- struct{}{}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if failureMode {
|
|
||||||
|
err := tc.recursiveNodeUpdate(path, tc.head)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Error during initial read of Zookeeper: %s", err)
|
||||||
failure()
|
failure()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user