diff options
author | Giuseppe Scrivano <gscrivan@redhat.com> | 2018-06-20 09:36:01 +0200 |
---|---|---|
committer | Giuseppe Scrivano <gscrivan@redhat.com> | 2018-06-20 09:36:04 +0200 |
commit | da44d8d5c839c7e09714495a7b121d8aa8664413 (patch) | |
tree | 1e051df749027b6587cb9b4de107f19c377790f6 /libpod/container_api.go | |
parent | f228cf73e0318f48c94ec4cd1b9b3115cfbb763a (diff) | |
download | podman-da44d8d5c839c7e09714495a7b121d8aa8664413.tar.gz podman-da44d8d5c839c7e09714495a7b121d8aa8664413.tar.bz2 podman-da44d8d5c839c7e09714495a7b121d8aa8664413.zip |
libpod: fix race with attach/start
Move the StartContainer call after the attach to the UNIX socket. It
solves a race where the StartContainer could be done earlier and a
short-lived container could already exit by the time we tried to
attach to the socket.
Closes: https://github.com/projectatomic/libpod/issues/835
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'libpod/container_api.go')
-rw-r--r-- | libpod/container_api.go | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go index 0ddccfe8e..96648ccf5 100644 --- a/libpod/container_api.go +++ b/libpod/container_api.go @@ -178,18 +178,12 @@ func (c *Container) StartAndAttach(ctx context.Context, streams *AttachStreams, // Attach to the container before starting it go func() { - if err := c.attach(streams, keys, resize); err != nil { + if err := c.attach(streams, keys, resize, true); err != nil { attachChan <- err } close(attachChan) }() - // Start the container - if err := c.start(); err != nil { - // TODO: interrupt the attach here if we error - return nil, err - } - return attachChan, nil } @@ -421,7 +415,7 @@ func (c *Container) Attach(streams *AttachStreams, keys string, resize <-chan re return errors.Wrapf(ErrCtrStateInvalid, "can only attach to created or running containers") } - return c.attach(streams, keys, resize) + return c.attach(streams, keys, resize, false) } // Mount mounts a container's filesystem on the host |