Skip to content

Commit

Permalink
container stop: kill conmon
Browse files Browse the repository at this point in the history
Old versions of conmon have a bug where they create the exit file before
closing open file descriptors causing a race condition when restarting
containers with open ports since we cannot bind the ports as they're not
yet closed by conmon.

Killing the old conmon PID is ~okay since it forces the FDs of old
conmons to be closed, while it's a NOP for newer versions which should
have exited already.

Signed-off-by: Valentin Rothberg <[email protected]>
  • Loading branch information
vrothberg committed Aug 5, 2019
1 parent 389a7b7 commit 909ab59
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1152,9 +1152,27 @@ func (c *Container) restartWithTimeout(ctx context.Context, timeout uint) (err e
c.newContainerEvent(events.Restart)

if c.state.State == define.ContainerStateRunning {
conmonPID := c.state.ConmonPID
if err := c.stop(timeout); err != nil {
return err
}
// Old versions of conmon have a bug where they create the exit file before
// closing open file descriptors causing a race condition when restarting
// containers with open ports since we cannot bind the ports as they're not
// yet closed by conmon.
//
// Killing the old conmon PID is ~okay since it forces the FDs of old conmons
// to be closed, while it's a NOP for newer versions which should have
// exited already.
if conmonPID != 0 {
// Ignore errors from FindProcess() as conmon could already have exited.
p, err := os.FindProcess(conmonPID)
if p != nil && err == nil {
if err = p.Kill(); err != nil {
logrus.Debugf("error killing conmon process: %v", err)
}
}
}
}
defer func() {
if err != nil {
Expand Down

0 comments on commit 909ab59

Please sign in to comment.