Skip to content

Commit 76881a2

Browse files
Fix Range() iteration
The function passed into the Range function of sync.Map will stop the iteration if false is returned. This commit makes sure we iterate through all elements in the map. Signed-off-by: Gabriel Adrian Samfira <[email protected]>
1 parent e093fbd commit 76881a2

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

cmd/containerd-shim-runhcs-v1/pod.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,9 @@ func (p *pod) KillTask(ctx context.Context, tid, eid string, signal uint32, all
380380
return wt.KillExec(ctx, eid, signal, all)
381381
})
382382

383-
// iterate all
384-
return false
383+
// Iterate all. Returning false stops the iteration. See:
384+
// https://pkg.go.dev/sync#Map.Range
385+
return true
385386
})
386387
}
387388
eg.Go(func() error {

cmd/containerd-shim-runhcs-v1/task_hcs.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,9 @@ func (ht *hcsTask) KillExec(ctx context.Context, eid string, signal uint32, all
536536
}).Warn("failed to kill exec in task")
537537
}
538538

539-
// iterate all
540-
return false
539+
// Iterate all. Returning false stops the iteration. See:
540+
// https://pkg.go.dev/sync#Map.Range
541+
return true
541542
})
542543
}
543544
if signal == 0x9 && eid == "" && ht.host != nil {
@@ -578,8 +579,9 @@ func (ht *hcsTask) DeleteExec(ctx context.Context, eid string) (int, uint32, tim
578579
ex.ForceExit(ctx, 1)
579580
}
580581

581-
// iterate next
582-
return false
582+
// Iterate all. Returning false stops the iteration. See:
583+
// https://pkg.go.dev/sync#Map.Range
584+
return true
583585
})
584586
}
585587
switch state := e.State(); state {
@@ -617,8 +619,9 @@ func (ht *hcsTask) Pids(ctx context.Context) ([]runhcsopts.ProcessDetails, error
617619
ex := value.(shimExec)
618620
pidMap[ex.Pid()] = ex.ID()
619621

620-
// Iterate all
621-
return false
622+
// Iterate all. Returning false stops the iteration. See:
623+
// https://pkg.go.dev/sync#Map.Range
624+
return true
622625
})
623626
pidMap[ht.init.Pid()] = ht.init.ID()
624627

@@ -699,8 +702,9 @@ func (ht *hcsTask) waitForHostExit() {
699702
ex := value.(shimExec)
700703
ex.ForceExit(ctx, 1)
701704

702-
// iterate all
703-
return false
705+
// Iterate all. Returning false stops the iteration. See:
706+
// https://pkg.go.dev/sync#Map.Range
707+
return true
704708
})
705709
ht.init.ForceExit(ctx, 1)
706710
ht.closeHost(ctx)

0 commit comments

Comments
 (0)