From d26fd5c97b0c505f5cb36f719abd6ccc8130bdc9 Mon Sep 17 00:00:00 2001 From: Shihao Xia Date: Wed, 5 Jan 2022 05:51:06 -0500 Subject: [PATCH] fix potential goroutine leaks (#10057) Signed-off-by: Shihao Xia --- discovery/legacymanager/manager_test.go | 7 +++++-- discovery/manager_test.go | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/discovery/legacymanager/manager_test.go b/discovery/legacymanager/manager_test.go index ce2278d23..57c82b72a 100644 --- a/discovery/legacymanager/manager_test.go +++ b/discovery/legacymanager/manager_test.go @@ -668,13 +668,16 @@ func TestTargetUpdatesOrder(t *testing.T) { discoveryManager.updatert = 100 * time.Millisecond var totalUpdatesCount int - provUpdates := make(chan []*targetgroup.Group) for _, up := range tc.updates { - go newMockDiscoveryProvider(up...).Run(ctx, provUpdates) if len(up) > 0 { totalUpdatesCount += len(up) } } + provUpdates := make(chan []*targetgroup.Group, totalUpdatesCount) + + for _, up := range tc.updates { + go newMockDiscoveryProvider(up...).Run(ctx, provUpdates) + } for x := 0; x < totalUpdatesCount; x++ { select { diff --git a/discovery/manager_test.go b/discovery/manager_test.go index 80ea1008e..970168b0f 100644 --- a/discovery/manager_test.go +++ b/discovery/manager_test.go @@ -668,13 +668,16 @@ func TestTargetUpdatesOrder(t *testing.T) { discoveryManager.updatert = 100 * time.Millisecond var totalUpdatesCount int - provUpdates := make(chan []*targetgroup.Group) for _, up := range tc.updates { - go newMockDiscoveryProvider(up...).Run(ctx, provUpdates) if len(up) > 0 { totalUpdatesCount += len(up) } } + provUpdates := make(chan []*targetgroup.Group, totalUpdatesCount) + + for _, up := range tc.updates { + go newMockDiscoveryProvider(up...).Run(ctx, provUpdates) + } for x := 0; x < totalUpdatesCount; x++ { select {