From 728743eb2858764df05fbb012cb03eb7c6cb0423 Mon Sep 17 00:00:00 2001 From: Quan Tian Date: Fri, 4 Jun 2021 19:13:53 +0800 Subject: [PATCH] Fix cleanup context of teardownPodNetwork Similar to other deferred cleanup operations, teardownPodNetwork should use a different context as the original context may have expired, otherwise CNI wouldn't been invoked, leading to leak of network resources, e.g. IP addresses. Signed-off-by: Quan Tian --- pkg/cri/server/sandbox_run.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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) }