Merge pull request #1140 from pescox/pr/worker-goroutine-leak

Pr/worker goroutine leak
This commit is contained in:
yangkaa 2022-02-09 19:37:00 -06:00 committed by GitHub
commit 85b95136d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 10 deletions

View File

@ -89,7 +89,7 @@ func (k *kubernetesDiscover) Discover(ctx context.Context, update chan *v1alpha1
if err != nil {
return nil, fmt.Errorf("load kubernetes service failure %s", err.Error())
}
re, err := k.client.CoreV1().Endpoints(namespace).Watch(ctx, metav1.ListOptions{LabelSelector: labels.FormatLabels(service.Spec.Selector)})
re, err := k.client.CoreV1().Endpoints(namespace).Watch(ctx, metav1.ListOptions{LabelSelector: labels.FormatLabels(service.Spec.Selector), Watch: true})
if err != nil {
return nil, fmt.Errorf("watch kubernetes endpoints failure %s", err.Error())
}
@ -111,7 +111,6 @@ func (k *kubernetesDiscover) Discover(ctx context.Context, update chan *v1alpha1
logrus.Errorf("discover kubernetes endpoints %s change failure %s", component.Spec.EndpointSource.KubernetesService.Name, err.Error())
}
}()
return k.DiscoverOne(ctx)
}
}
}

View File

@ -31,14 +31,7 @@ func (w *Worker) Start() {
}()
w.stoped = false
logrus.Infof("discover endpoint list worker %s/%s started", w.discover.GetComponent().Namespace, w.discover.GetComponent().Name)
for {
w.discover.Discover(w.ctx, w.updateChan)
select {
case <-w.ctx.Done():
return
default:
}
}
w.discover.Discover(w.ctx, w.updateChan)
}
// UpdateDiscover -