Skip to content

Commit 051f2ec

Browse files
committed
fix: panic in async execution flow
1 parent 55f0281 commit 051f2ec

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

pkg/cluster/ClusterService.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,8 @@ func (impl *ClusterServiceImpl) updateConnectionStatusForVirtualCluster(respMap
771771
func (impl *ClusterServiceImpl) ConnectClustersInBatch(clusters []*bean.ClusterBean, clusterExistInDb bool) {
772772
var wg sync.WaitGroup
773773
respMap := &sync.Map{}
774-
for idx, cluster := range clusters {
774+
for idx := range clusters {
775+
cluster := clusters[idx]
775776
if cluster.IsVirtualCluster {
776777
impl.updateConnectionStatusForVirtualCluster(respMap, cluster.Id, cluster.ClusterName)
777778
continue

pkg/k8s/K8sCommonService.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,17 +404,18 @@ func (impl *K8sCommonServiceImpl) getManifestsByBatch(ctx context.Context, reque
404404
var wg sync.WaitGroup
405405
for j := 0; j < batchSize; j++ {
406406
wg.Add(1)
407-
runnableFunc := func(j int) {
407+
runnableFunc := func(index int) {
408408
resp := bean5.BatchResourceResponse{}
409-
response, err := impl.GetResource(ctx, &requests[i+j])
409+
response, err := impl.GetResource(ctx, &requests[index])
410410
if response != nil {
411411
resp.ManifestResponse = response.ManifestResponse
412412
}
413413
resp.Err = err
414-
res[i+j] = resp
414+
res[index] = resp
415415
wg.Done()
416416
}
417-
impl.asyncRunnable.Execute(func() { runnableFunc(j) })
417+
index := i + j
418+
impl.asyncRunnable.Execute(func() { runnableFunc(index) })
418419
}
419420
wg.Wait()
420421
i += batchSize

0 commit comments

Comments
 (0)