Skip to content

Commit

Permalink
Merge pull request apache#129 from pantianying/tmp1
Browse files Browse the repository at this point in the history
Fix: bug of UnregisterEvent
  • Loading branch information
AlexStocks authored Jul 16, 2019
2 parents e582cc0 + 0ecb948 commit 197f248
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions remoting/zookeeper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,29 +298,26 @@ func (z *ZookeeperClient) UnregisterEvent(zkPath string, event *chan struct{}) {
if zkPath == "" {
return
}

z.Lock()
for {
a, ok := z.eventRegistry[zkPath]
if !ok {
break
}
for i, e := range a {
if e == event {
arr := a
a = append(arr[:i], arr[i+1:]...)
logger.Debugf("zkClient{%s} unregister event{path:%s, event:%p}", z.name, zkPath, event)
}
}
logger.Debugf("after zkClient{%s} unregister event{path:%s, event:%p}, array length %d",
z.name, zkPath, event, len(a))
if len(a) == 0 {
delete(z.eventRegistry, zkPath)
} else {
z.eventRegistry[zkPath] = a
defer z.Unlock()
infoList, ok := z.eventRegistry[zkPath]
if !ok {
return
}
for i, e := range infoList {
if e == event {
arr := infoList
infoList = append(arr[:i], arr[i+1:]...)
logger.Debugf("zkClient{%s} unregister event{path:%s, event:%p}", z.name, zkPath, event)
}
}
z.Unlock()
logger.Debugf("after zkClient{%s} unregister event{path:%s, event:%p}, array length %d",
z.name, zkPath, event, len(infoList))
if len(infoList) == 0 {
delete(z.eventRegistry, zkPath)
} else {
z.eventRegistry[zkPath] = infoList
}
}

func (z *ZookeeperClient) Done() <-chan struct{} {
Expand Down

0 comments on commit 197f248

Please sign in to comment.