Skip to content

Commit

Permalink
nacos stop cannot cancel subscription (#3173)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenliang committed Mar 20, 2024
1 parent 1ab258e commit cd9857f
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions contrib/registry/nacos/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

0 comments on commit cd9857f

Please sign in to comment.