Skip to content

Commit

Permalink
fix(contrib/registry/nacos): Abnormal blocking of the Subscribe and N…
Browse files Browse the repository at this point in the history
…ext methods. (#3320)

* fix(contrib/registry/nacos):Abnormal blocking of the Subscribe and Next methods.

This submission can solve the channel blocking problem during service discovery, as well as the channel message missing problem when the GRPC idle state changes.

The first scenario is when both the configuration center and registration center are initialized at the same time during service startup, and the SubscribeCallback method will be triggered twice, throwing the error "over time discovering the creation of observers", resulting in a discovery failure. The second scenario occurs after NotLoadCacheAtStart: true. When grpc exits the idle state, calling newWatcher again will not trigger the SubscribeCallback method, causing the Next function to be blocked and the service to be unable to communicate.

* Another implementation, the effect remains unchanged
  • Loading branch information
guoquanwei committed May 16, 2024
1 parent d0d5761 commit fbac5fa
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion contrib/registry/nacos/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,17 @@ func newWatcher(ctx context.Context, cli naming_client.INamingClient, serviceNam
Clusters: clusters,
GroupName: groupName,
SubscribeCallback: func(services []model.SubscribeService, err error) {
w.watchChan <- struct{}{}
select {
case w.watchChan <- struct{}{}:
default:
}
},
}
e := w.cli.Subscribe(w.subscribeParam)
select {
case w.watchChan <- struct{}{}:
default:
}
return w, e
}

Expand Down

0 comments on commit fbac5fa

Please sign in to comment.