Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
sandbox: Stop and clean up containers that fail to create
Browse files Browse the repository at this point in the history
A container that is created and added to a sandbox can still fail
the final creation steps. In this case, the container must be stopped
and have its resources cleaned up to prevent leaking sandbox mounts.

Fixes #2816

Signed-off-by: Evan Foster <efoster@adobe.com>
  • Loading branch information
Evan Foster committed Jul 13, 2020
1 parent a885b1b commit 00e0ada
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2016 Intel Corporation
// Copyright (c) 2020 Adobe Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -1166,6 +1167,11 @@ func (s *Sandbox) CreateContainer(contConfig ContainerConfig) (VCContainer, erro
defer func() {
// Rollback if error happens.
if err != nil {
s.Logger().Warningf("Container %q could not be created, stopping it", contConfig.ID)
if err = c.stop(true); err != nil {
s.Logger().WithError(err).WithField("container-id", c.id).WithField("sandboxid", s.id).Warning("Could not delete container")
}
s.Logger().WithField("container-id", c.id).WithField("sandboxid", s.id).Info("Container was stopped. Removing from sandbox store")
s.removeContainer(c.id)
}
}()
Expand Down

0 comments on commit 00e0ada

Please sign in to comment.