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
Show file tree
Hide file tree
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
add code
  • Loading branch information
pantianying committed Nov 30, 2019
commit d978b86aa6fe56f749332d993831e5142d286fe7
4 changes: 3 additions & 1 deletion registry/zookeeper/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ type RegistryConfigurationListener struct {
client *zk.ZookeeperClient
registry *zkRegistry
events chan *config_center.ConfigChangeEvent
isClosed bool
}

func NewRegistryConfigurationListener(client *zk.ZookeeperClient, reg *zkRegistry) *RegistryConfigurationListener {
reg.wg.Add(1)
return &RegistryConfigurationListener{client: client, registry: reg, events: make(chan *config_center.ConfigChangeEvent, 32)}
return &RegistryConfigurationListener{client: client, registry: reg, events: make(chan *config_center.ConfigChangeEvent, 32), isClosed: false}
}
func (l *RegistryConfigurationListener) Process(configType *config_center.ConfigChangeEvent) {
l.events <- configType
Expand Down Expand Up @@ -114,6 +115,7 @@ func (l *RegistryConfigurationListener) Close() {
* if the registry is not available, it means that the registry has been destroy
* so we don't need to call Done(), or it will cause the negative count panic for registry.wg
*/
l.isClosed = true
l.registry.wg.Done()
}
}
Expand Down
4 changes: 4 additions & 0 deletions registry/zookeeper/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ func (r *zkRegistry) getListener(conf *common.URL) (*RegistryConfigurationListen
)

r.listenerLock.Lock()
if r.configListener.isClosed {
return nil, perrors.New("configListener already been closed")
r.listenerLock.Unlock()
}
zkListener = r.configListener
r.listenerLock.Unlock()
if r.listener == nil {
Expand Down