stop: limit number of maximum stop worker to 128
set a hard limit on the number of stop workers.  We should never
really hit this limit, as it means a pod has more that 128 running
containers.
@@ -59,8 +59,14 @@ func (s *Server) stopPodSandbox(ctx context.Context, req *pb.StopPodSandboxReque
// Clean up sandbox networking and close its network namespace.
s.networkStop(sb)
+ const maxWorkers = 128
var waitGroup errgroup.Group
- for _, ctr := range containers {
+ for i := 0; i < len(containers); i += maxWorkers {
+ max := i + maxWorkers
+ if len(containers) < max {
+ max = len(containers)
+ }
+ for _, ctr := range containers[i:max] {
cStatus := s.Runtime().ContainerStatus(ctr)
if cStatus.Status != oci.ContainerStateStopped {
if ctr.ID() == podInfraContainer.ID() {
@@ -87,6 +93,7 @@ func (s *Server) stopPodSandbox(ctx context.Context, req *pb.StopPodSandboxReque
if err := waitGroup.Wait(); err != nil {
return nil, err
}
+ }
podInfraStatus := s.Runtime().ContainerStatus(podInfraContainer)
if podInfraStatus.Status != oci.ContainerStateStopped {
