diff --git a/contrib/registry/nacos/watcher.go b/contrib/registry/nacos/watcher.go index 78b4fc21b..6fd59b378 100644 --- a/contrib/registry/nacos/watcher.go +++ b/contrib/registry/nacos/watcher.go @@ -14,14 +14,15 @@ import ( var _ registry.Watcher = (*watcher)(nil) type watcher struct { - serviceName string - clusters []string - groupName string - ctx context.Context - cancel context.CancelFunc - watchChan chan struct{} - cli naming_client.INamingClient - kind string + serviceName string + clusters []string + groupName string + ctx context.Context + cancel context.CancelFunc + watchChan chan struct{} + cli naming_client.INamingClient + kind string + subscribeParam *vo.SubscribeParam } func newWatcher(ctx context.Context, cli naming_client.INamingClient, serviceName, groupName, kind string, clusters []string) (*watcher, error) { @@ -35,14 +36,15 @@ func newWatcher(ctx context.Context, cli naming_client.INamingClient, serviceNam } w.ctx, w.cancel = context.WithCancel(ctx) - e := w.cli.Subscribe(&vo.SubscribeParam{ + w.subscribeParam = &vo.SubscribeParam{ ServiceName: serviceName, Clusters: clusters, GroupName: groupName, SubscribeCallback: func(services []model.SubscribeService, err error) { w.watchChan <- struct{}{} }, - }) + } + e := w.cli.Subscribe(w.subscribeParam) return w, e } @@ -78,10 +80,7 @@ func (w *watcher) Next() ([]*registry.ServiceInstance, error) { } func (w *watcher) Stop() error { + err := w.cli.Unsubscribe(w.subscribeParam) w.cancel() - return w.cli.Unsubscribe(&vo.SubscribeParam{ - ServiceName: w.serviceName, - GroupName: w.groupName, - Clusters: w.clusters, - }) + return err }