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: nacos stop cannot cancel subscription #3173

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Changes from all commits
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
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
}
Loading