Skip to content

Commit

Permalink
fix zk trigger reconnect on first zk connection (#62)
Browse files Browse the repository at this point in the history
* change code more readable

* fix nacos ut failed

* fix nacos ut

* fix zk reconn

Co-authored-by: 文徐 <[email protected]>
  • Loading branch information
wenxuwan and wenxuwan authored Jul 10, 2021
1 parent 7870c5b commit c144977
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions database/kv/zk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type ZookeeperClient struct {
Wait sync.WaitGroup
valid uint32
share bool
initialized uint32
reconnectCh chan struct{}
eventRegistry map[string][]*chan struct{}
eventRegistryLock sync.RWMutex
Expand Down Expand Up @@ -243,8 +244,11 @@ func (d *DefaultHandler) HandleZkEvent(z *ZookeeperClient) {
}
if event.State == zk.StateHasSession {
atomic.StoreUint32(&z.valid, 1)
close(z.reconnectCh)
z.reconnectCh = make(chan struct{})
//if this is the first connection, don't trigger reconnect event
if !atomic.CompareAndSwapUint32(&z.initialized, 0, 1) {
close(z.reconnectCh)
z.reconnectCh = make(chan struct{})
}
}
z.eventRegistryLock.RLock()
if a, ok := z.eventRegistry[event.Path]; ok && 0 < len(a) {
Expand Down

0 comments on commit c144977

Please sign in to comment.