diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-05-16 01:08:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-16 01:08:05 +0200 |
commit | 95d90c1de7035ded6a4a05e6e3a80f0b32cbdf39 (patch) | |
tree | 6b936999c1110e086cbc805346b5c4932a0b31c2 /libpod/container_api.go | |
parent | 7ede1594652003e1ec545dc5c98c44142dcdd7c3 (diff) | |
parent | 5b3f3c411058ecd22431b119a2db6e8ce7cf111b (diff) | |
download | podman-95d90c1de7035ded6a4a05e6e3a80f0b32cbdf39.tar.gz podman-95d90c1de7035ded6a4a05e6e3a80f0b32cbdf39.tar.bz2 podman-95d90c1de7035ded6a4a05e6e3a80f0b32cbdf39.zip |
Merge pull request #3127 from mheon/fix_start_race
Ensure that start() in StartAndAttach() is locked
Diffstat (limited to 'libpod/container_api.go')
-rw-r--r-- | libpod/container_api.go | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go index 5bb610aab..06a31da11 100644 --- a/libpod/container_api.go +++ b/libpod/container_api.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "os" "strconv" + "sync" "time" "github.com/containers/libpod/libpod/driver" @@ -119,13 +120,20 @@ func (c *Container) StartAndAttach(ctx context.Context, streams *AttachStreams, attachChan := make(chan error) + // We need to ensure that we don't return until start() fired in attach. + // Use a WaitGroup to sync this. + wg := new(sync.WaitGroup) + wg.Add(1) + // Attach to the container before starting it go func() { - if err := c.attach(streams, keys, resize, true); err != nil { + if err := c.attach(streams, keys, resize, true, wg); err != nil { attachChan <- err } close(attachChan) }() + + wg.Wait() c.newContainerEvent(events.Attach) return attachChan, nil } @@ -398,7 +406,7 @@ func (c *Container) Attach(streams *AttachStreams, keys string, resize <-chan re return errors.Wrapf(ErrCtrStateInvalid, "can only attach to created or running containers") } defer c.newContainerEvent(events.Attach) - return c.attach(streams, keys, resize, false) + return c.attach(streams, keys, resize, false, nil) } // Mount mounts a container's filesystem on the host |