From 0c3bed119b16e90534172410f70713591ecafc4c Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Wed, 13 May 2020 09:17:36 -0400 Subject: Remove exec sessions on container restart With APIv2, we cannot guarantee that exec sessions will be removed cleanly on exit (Docker does not include an API for removing exec sessions, instead using a timer-based reaper which we cannot easily replicate). This is part 1 of a 2-part approach to providing a solution to this. This ensures that exec sessions will be reaped, at the very least, on container restart, which takes care of any that were not properly removed during the run of a container. Signed-off-by: Matthew Heon --- libpod/container_internal.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'libpod/container_internal.go') diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 5baa5fc1c..13b986cac 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -1011,6 +1011,14 @@ func (c *Container) init(ctx context.Context, retainRetries bool) error { logrus.Debugf("Created container %s in OCI runtime", c.ID()) + // Remove any exec sessions leftover from a potential prior run. + if len(c.state.ExecSessions) > 0 { + if err := c.runtime.state.RemoveContainerExecSessions(c); err != nil { + logrus.Errorf("Error removing container %s exec sessions from DB: %v", err) + } + c.state.ExecSessions = make(map[string]*ExecSession) + } + c.state.ExitCode = 0 c.state.Exited = false c.state.State = define.ContainerStateCreated -- cgit v1.2.3-54-g00ecf From a6d9cf9a5e46ff3a8f1f8d2515c12ff6d31056b4 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 14 May 2020 17:01:49 -0400 Subject: Fix lint Signed-off-by: Matthew Heon --- libpod/container_internal.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libpod/container_internal.go') diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 13b986cac..909ad9851 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -1014,7 +1014,7 @@ func (c *Container) init(ctx context.Context, retainRetries bool) error { // Remove any exec sessions leftover from a potential prior run. if len(c.state.ExecSessions) > 0 { if err := c.runtime.state.RemoveContainerExecSessions(c); err != nil { - logrus.Errorf("Error removing container %s exec sessions from DB: %v", err) + logrus.Errorf("Error removing container %s exec sessions from DB: %v", c.ID(), err) } c.state.ExecSessions = make(map[string]*ExecSession) } -- cgit v1.2.3-54-g00ecf