Skip to content

Commit fbac5fa

Browse files
authored
fix(contrib/registry/nacos): Abnormal blocking of the Subscribe and Next 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
1 parent d0d5761 commit fbac5fa

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

contrib/registry/nacos/watcher.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,17 @@ func newWatcher(ctx context.Context, cli naming_client.INamingClient, serviceNam
4141
Clusters: clusters,
4242
GroupName: groupName,
4343
SubscribeCallback: func(services []model.SubscribeService, err error) {
44-
w.watchChan <- struct{}{}
44+
select {
45+
case w.watchChan <- struct{}{}:
46+
default:
47+
}
4548
},
4649
}
4750
e := w.cli.Subscribe(w.subscribeParam)
51+
select {
52+
case w.watchChan <- struct{}{}:
53+
default:
54+
}
4855
return w, e
4956
}
5057

0 commit comments

Comments
 (0)