summaryrefslogtreecommitdiff
path: root/pkg/api/handlers
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2021-03-26 10:54:33 -0400
committerDaniel J Walsh <dwalsh@redhat.com>2021-03-26 15:15:17 -0400
commitdcabf6dd717ad495ba71d2788a64255defb852fd (patch)
treebd2ee4042feadd0b84a2b4076b2d7e948f4855b7 /pkg/api/handlers
parentc81e273835303664d62c4e958a7f34877c05ed49 (diff)
downloadpodman-dcabf6dd717ad495ba71d2788a64255defb852fd.tar.gz
podman-dcabf6dd717ad495ba71d2788a64255defb852fd.tar.bz2
podman-dcabf6dd717ad495ba71d2788a64255defb852fd.zip
Remove resize race condition
Since podman-remote resize requests can come in at random times, this generates a real potential for race conditions. We should only be attempting to resize TTY on running containers, but the containers can go from running to stopped at any time, and returning an error to the caller is just causing noice. This change will basically ignore requests to resize terminals if the container is not running and return the caller to success. All other callers will still return failure. Fixes: https://github.com/containers/podman/issues/9831 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'pkg/api/handlers')
-rw-r--r--pkg/api/handlers/compat/resize.go22
1 files changed, 14 insertions, 8 deletions
diff --git a/pkg/api/handlers/compat/resize.go b/pkg/api/handlers/compat/resize.go
index 1bf7ad460..23ed33a22 100644
--- a/pkg/api/handlers/compat/resize.go
+++ b/pkg/api/handlers/compat/resize.go
@@ -19,8 +19,9 @@ func ResizeTTY(w http.ResponseWriter, r *http.Request) {
// /containers/{id}/resize
query := struct {
- Height uint16 `schema:"h"`
- Width uint16 `schema:"w"`
+ Height uint16 `schema:"h"`
+ Width uint16 `schema:"w"`
+ IgnoreNotRunning bool `schema:"running"`
}{
// override any golang type defaults
}
@@ -48,14 +49,17 @@ func ResizeTTY(w http.ResponseWriter, r *http.Request) {
if state, err := ctnr.State(); err != nil {
utils.InternalServerError(w, errors.Wrapf(err, "cannot obtain container state"))
return
- } else if state != define.ContainerStateRunning {
+ } else if state != define.ContainerStateRunning && !query.IgnoreNotRunning {
utils.Error(w, "Container not running", http.StatusConflict,
fmt.Errorf("container %q in wrong state %q", name, state.String()))
return
}
+ // If container is not running, ignore since this can be a race condition, and is expected
if err := ctnr.AttachResize(sz); err != nil {
- utils.InternalServerError(w, errors.Wrapf(err, "cannot resize container"))
- return
+ if errors.Cause(err) != define.ErrCtrStateInvalid || !query.IgnoreNotRunning {
+ utils.InternalServerError(w, errors.Wrapf(err, "cannot resize container"))
+ return
+ }
}
// This is not a 204, even though we write nothing, for compatibility
// reasons.
@@ -70,14 +74,16 @@ func ResizeTTY(w http.ResponseWriter, r *http.Request) {
if state, err := ctnr.State(); err != nil {
utils.InternalServerError(w, errors.Wrapf(err, "cannot obtain session container state"))
return
- } else if state != define.ContainerStateRunning {
+ } else if state != define.ContainerStateRunning && !query.IgnoreNotRunning {
utils.Error(w, "Container not running", http.StatusConflict,
fmt.Errorf("container %q in wrong state %q", name, state.String()))
return
}
if err := ctnr.ExecResize(name, sz); err != nil {
- utils.InternalServerError(w, errors.Wrapf(err, "cannot resize session"))
- return
+ if errors.Cause(err) != define.ErrCtrStateInvalid || !query.IgnoreNotRunning {
+ utils.InternalServerError(w, errors.Wrapf(err, "cannot resize session"))
+ return
+ }
}
// This is not a 204, even though we write nothing, for compatibility
// reasons.