diff options
author | Matthew Heon <mheon@redhat.com> | 2022-04-13 14:04:05 -0400 |
---|---|---|
committer | Matthew Heon <mheon@redhat.com> | 2022-04-13 14:04:05 -0400 |
commit | 02b7eeff62224333a6ec768998a6b5db8cd7dc4d (patch) | |
tree | 59a4090d2b1cf44e05ba91c6c77a25091aa93ade /pkg/api | |
parent | f6ce14b066ad57a86642f22c15ac42020fc0f660 (diff) | |
download | podman-02b7eeff62224333a6ec768998a6b5db8cd7dc4d.tar.gz podman-02b7eeff62224333a6ec768998a6b5db8cd7dc4d.tar.bz2 podman-02b7eeff62224333a6ec768998a6b5db8cd7dc4d.zip |
Allow HTTP attach to stopped containers
There's a potential race condition where we attempt to attach to
a container immediately after it's been stopped, but before the
cleanup process has run on it. The existing code doesn't allow an
attach to containers in the Stopped state (cleanup process has
not run) but does allow an attach to containers in the Exited
state (cleanup process has run). This doesn't make very much
sense and there's no technical reason to restrict attach to only
Exited containers, so allow attaching to Stopped containers.
[NO NEW TESTS NEEDED] Testing this is very racy - we need to get
in before the cleanup process runs, which isn't really
deterministic when we're invoked from a script - like the CI
tests.
Signed-off-by: Matthew Heon <mheon@redhat.com>
Diffstat (limited to 'pkg/api')
-rw-r--r-- | pkg/api/handlers/compat/containers_attach.go | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/pkg/api/handlers/compat/containers_attach.go b/pkg/api/handlers/compat/containers_attach.go index 027dadaa3..c8905808f 100644 --- a/pkg/api/handlers/compat/containers_attach.go +++ b/pkg/api/handlers/compat/containers_attach.go @@ -83,7 +83,7 @@ func AttachContainer(w http.ResponseWriter, r *http.Request) { return } // For Docker compatibility, we need to re-initialize containers in these states. - if state == define.ContainerStateConfigured || state == define.ContainerStateExited { + if state == define.ContainerStateConfigured || state == define.ContainerStateExited || state == define.ContainerStateStopped { if err := ctr.Init(r.Context(), ctr.PodID() != ""); err != nil { utils.Error(w, http.StatusConflict, errors.Wrapf(err, "error preparing container %s for attach", ctr.ID())) return |