diff --git a/contrib/registry/polaris/registry.go b/contrib/registry/polaris/registry.go index e968fe386..5ad520afc 100644 --- a/contrib/registry/polaris/registry.go +++ b/contrib/registry/polaris/registry.go @@ -332,6 +332,7 @@ type Watcher struct { Cancel context.CancelFunc Channel <-chan model.SubScribeEvent ServiceInstances []*registry.ServiceInstance + first bool } func newWatcher(ctx context.Context, namespace string, serviceName string, consumer api.ConsumerAPI) (*Watcher, error) { @@ -350,6 +351,7 @@ func newWatcher(ctx context.Context, namespace string, serviceName string, consu w := &Watcher{ Namespace: namespace, ServiceName: serviceName, + first: true, Channel: watchServiceResponse.EventChannel, ServiceInstances: instancesToServiceInstances(watchServiceResponse.GetAllInstancesResp.GetInstances()), } @@ -362,6 +364,10 @@ func newWatcher(ctx context.Context, namespace string, serviceName string, consu // 2.any service instance changes found. // if the above two conditions are not met, it will block until context deadline exceeded or canceled func (w *Watcher) Next() ([]*registry.ServiceInstance, error) { + if w.first { + w.first = false + return w.ServiceInstances, nil + } select { case <-w.Ctx.Done(): return nil, w.Ctx.Err()