diff --git a/pkg/cri/server/sandbox_run.go b/pkg/cri/server/sandbox_run.go index cb83b5b5e..98bba7949 100644 --- a/pkg/cri/server/sandbox_run.go +++ b/pkg/cri/server/sandbox_run.go @@ -132,8 +132,10 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox sandbox.NetNSPath = sandbox.NetNS.GetPath() defer func() { if retErr != nil { + deferCtx, deferCancel := ctrdutil.DeferContext() + defer deferCancel() // Teardown network if an error is returned. - if err := c.teardownPodNetwork(ctx, sandbox); err != nil { + if err := c.teardownPodNetwork(deferCtx, sandbox); err != nil { log.G(ctx).WithError(err).Errorf("Failed to destroy network for sandbox %q", id) }