Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remote: always send resize before the container starts #10549

Merged
merged 1 commit into from
Jun 5, 2021

Conversation

Luap99
Copy link
Member

@Luap99 Luap99 commented Jun 3, 2021

There is race condition in the remote client attach logic. Because the
resize api call was handled in an extra goroutine the container was
started before the resize call happend. To fix this we have to call
resize in the same goroutine as attach. When the first resize is done
start a goroutine to listen on SIGWINCH in the background and resize
again if the signal is received.

Fixes #9859

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jun 3, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Luap99

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 3, 2021
@Luap99
Copy link
Member Author

Luap99 commented Jun 3, 2021

@edsantiago PTAL I think this fixes your issue.

@edsantiago
Copy link
Member

Running this infinite loop for the past five minutes, and it's passing so far:

$ while :;do bin/podman-remote run -it --rm quay.io/libpod/testimage:20210427 stty size;done

LGTM, thank you! And thank you for identifying and fixing the appropriate test!

@rhatdan
Copy link
Member

rhatdan commented Jun 3, 2021

@Luap99 If we don't have a thread watching for resize, then if the terminal actually get's resized, the container will now realize it. Have you tried this out with this change.

@Luap99
Copy link
Member Author

Luap99 commented Jun 3, 2021

@rhatdan Yes the extra thread is still created and resizes when SIGWINCH is received. Only the first resize is made from the attach thread.

@rhatdan
Copy link
Member

rhatdan commented Jun 3, 2021

LGTM

@@ -71,14 +62,6 @@ func ResizeTTY(w http.ResponseWriter, r *http.Request) {
utils.SessionNotFound(w, name, err)
return
}
if state, err := ctnr.State(); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this bit is still reasonable to hit - exec sessions in a non-running container will never happen.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this back. It looks podman exec -it con1 stty size is broken as well but for both local and remote.

@Luap99 Luap99 force-pushed the fix-9859 branch 2 times, most recently from be0f47f to d747ef7 Compare June 4, 2021 12:15
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 {
if errors.Cause(err) != define.ErrCtrStateInvalid || !query.IgnoreNotRunning {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we probably need to catch define.ErrCtrStateInvalid and return a http.StatusConflict down here. It should be a lot more forgiving than the above check, which only allows Running (we can also resize Created containers, and probably Paused containers as well, I forget) but ensures we're still returning good HTTP status codes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the http status code, this is used for the compat api as well and the docker api does not specify 409.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@mheon
Copy link
Member

mheon commented Jun 4, 2021

One more nit then LGTM

There is race condition in the remote client attach logic. Because the
resize api call was handled in an extra goroutine the container was
started before the resize call happend. To fix this we have to call
resize in the same goroutine as attach. When the first resize is done
start a goroutine to listen on SIGWINCH in the background and resize
again if the signal is received.

Fixes containers#9859

Signed-off-by: Paul Holzinger <[email protected]>
@mheon
Copy link
Member

mheon commented Jun 4, 2021

I think the compose test flaked - restarted

/lgtm
/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 4, 2021
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jun 4, 2021
@edsantiago
Copy link
Member

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 5, 2021
@openshift-merge-robot openshift-merge-robot merged commit 1e006a5 into containers:master Jun 5, 2021
@rhatdan
Copy link
Member

rhatdan commented Jun 7, 2021

Nice work @Luap99. This is a very old issue that @edsantiago has wanted fix for a while.

@Luap99 Luap99 deleted the fix-9859 branch June 7, 2021 13:30
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 23, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

race: podman-remote run -it : stty: standard input
5 participants