diff --git a/server/sandbox_network.go b/server/sandbox_network.go index d42b28bea1a..888cfa8fc02 100644 --- a/server/sandbox_network.go +++ b/server/sandbox_network.go @@ -42,7 +42,8 @@ func (s *Server) networkStart(ctx context.Context, sb *sandbox.Sandbox) (podIPs defer func() { if retErr != nil { log.Infof(ctx, "networkStart: stopping network for sandbox %s", sb.ID()) - if err2 := s.networkStop(startCtx, sb); err2 != nil { + // use a new context to prevent an expired context from preventing a stop + if err2 := s.networkStop(context.Background(), sb); err2 != nil { log.Errorf(ctx, "error stopping network on cleanup: %v", err2) } } diff --git a/server/sandbox_run_linux.go b/server/sandbox_run_linux.go index 0c8c7182940..41b2284ca8d 100644 --- a/server/sandbox_run_linux.go +++ b/server/sandbox_run_linux.go @@ -725,7 +725,8 @@ func (s *Server) runPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest } cleanupFuncs = append(cleanupFuncs, func() { log.Infof(ctx, "runSandbox: in manageNSLifecycle, stopping network for sandbox %s", sb.ID()) - if err2 := s.networkStop(ctx, sb); err2 != nil { + // use a new context to prevent an expired context from preventing a stop + if err2 := s.networkStop(context.Background(), sb); err2 != nil { log.Errorf(ctx, "error stopping network on cleanup: %v", err2) } }) @@ -955,7 +956,8 @@ func (s *Server) runPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest } cleanupFuncs = append(cleanupFuncs, func() { log.Infof(ctx, "runSandbox: stopping network for sandbox %s when not manageNSLifecycle", sb.ID()) - if err2 := s.networkStop(ctx, sb); err2 != nil { + // use a new context to prevent an expired context from preventing a stop + if err2 := s.networkStop(context.Background(), sb); err2 != nil { log.Errorf(ctx, "error stopping network on cleanup: %v", err2) } })