Skip to content

Commit 31ecdf7

Browse files
committed
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 <[email protected]> (cherry picked from commit 728743e)
1 parent f5f2b68 commit 31ecdf7

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

pkg/cri/server/sandbox_run.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
132132
sandbox.NetNSPath = sandbox.NetNS.GetPath()
133133
defer func() {
134134
if retErr != nil {
135+
deferCtx, deferCancel := ctrdutil.DeferContext()
136+
defer deferCancel()
135137
// Teardown network if an error is returned.
136-
if err := c.teardownPodNetwork(ctx, sandbox); err != nil {
138+
if err := c.teardownPodNetwork(deferCtx, sandbox); err != nil {
137139
log.G(ctx).WithError(err).Errorf("Failed to destroy network for sandbox %q", id)
138140
}
139141

0 commit comments

Comments
 (0)