Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: After disconnection with ZK registry, cosumer can't listen to provider changes #258

Merged
merged 8 commits into from
Dec 4, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix code
  • Loading branch information
pantianying committed Nov 23, 2019
commit e43dc296d343062fc5b1ca9f674533a2c095c904
17 changes: 13 additions & 4 deletions registry/zookeeper/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,22 +422,24 @@ func (r *zkRegistry) Subscribe(url *common.URL, notifyListener registry.NotifyLi
time.Sleep(time.Duration(RegistryConnDelay) * time.Second)
continue
}

n := 0
for {
n++
if serviceEvent, err := listener.Next(); err != nil {
logger.Warnf("Selector.watch() = error{%v}", perrors.WithStack(err))
if err.Error() == "listener stopped" {
if n == 1 {
listener.Close()
pantianying marked this conversation as resolved.
Show resolved Hide resolved
break
}
listener.Close()
break
} else {
logger.Infof("update begin, service event: %v", serviceEvent.String())
notifyListener.Notify(serviceEvent)
}

}
time.Sleep(1e9)
logger.Infof("wait for get subscribe listener, key{%v}", url.Key())
sleepWait(n)
}
}

Expand Down Expand Up @@ -492,3 +494,10 @@ func (r *zkRegistry) IsAvailable() bool {
return true
}
}
func sleepWait(n int) {
pantianying marked this conversation as resolved.
Show resolved Hide resolved
wait := time.Duration(200*n) * time.Millisecond
pantianying marked this conversation as resolved.
Show resolved Hide resolved
if wait > 3*time.Second {
pantianying marked this conversation as resolved.
Show resolved Hide resolved
wait = 3 * time.Second
}
time.Sleep(wait)
}