diff --git a/src/runtime/virtcontainers/api.go b/src/runtime/virtcontainers/api.go index 1927d4d077..6cda1db3db 100644 --- a/src/runtime/virtcontainers/api.go +++ b/src/runtime/virtcontainers/api.go @@ -70,18 +70,19 @@ func createSandboxFromConfig(ctx context.Context, sandboxConfig SandboxConfig, f } }() + // network rollback + defer func() { + if err != nil { + virtLog.Info("Removing network after failure in createSandbox") + s.removeNetwork(ctx) + } + }() + // Create the sandbox network if err = s.createNetwork(ctx); err != nil { return nil, err } - // network rollback - defer func() { - if err != nil { - s.removeNetwork(ctx) - } - }() - // Set the sandbox host cgroups. if err := s.setupResourceController(); err != nil { return nil, err