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

Fix closing stdin #1899

Merged
merged 1 commit into from Sep 14, 2023
Merged

Fix closing stdin #1899

merged 1 commit into from Sep 14, 2023

Conversation

rumpl
Copy link
Contributor

@rumpl rumpl commented Sep 13, 2023

moby tried updating hcsshim to 0.11.0 and we had some failures in our tests (see this PR).

We tracked the issue to this change, the close request wasn't forwarded any more if stdin is nil. This change moves the nil check to after the modify request, letting the process handle it.

@rumpl rumpl requested a review from a team as a code owner September 13, 2023 18:22
@neersighted
Copy link

We'd also like to backport this onto the 0.11 branch (and ideally tag a release) so we can pull this into moby/moby.

Comment on lines 447 to 453
if process.stdin == nil {
return nil
}

process.stdin.Close()
process.stdin = nil

Copy link
Contributor

Choose a reason for hiding this comment

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

A nit pick, but I'd suggest flipping the contents of the if statement so it matches the other two functions.

Suggested change
if process.stdin == nil {
return nil
}
process.stdin.Close()
process.stdin = nil
if process.stdin != nil {
process.stdin.Close()
process.stdin = nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Thanks

Send the modify request even if stdin is nil, let the process handle it

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
@TBBle
Copy link
Contributor

TBBle commented Sep 13, 2023

I'm separately curious why we don't (or don't need to) send HcsModifyProcess for the other stdio handles. Is it just that moby never calls it, so we haven't actually noticed that the contained process would not be notified for those handles? A quick look suggests the containerd shim doesn't call CloseStdout or CloseStderr either.

@helsaawy
Copy link
Contributor

I'm separately curious why we don't (or don't need to) send HcsModifyProcess for the other stdio handles. Is it just that moby never calls it, so we haven't actually noticed that the contained process would not be notified for those handles? A quick look suggests the containerd shim doesn't call CloseStdout or CloseStderr either.

I think since closing IO is (almost?) always followed closely by a Close which brings down the whole process (and therefore the stdout/err handles), its not needed, and we really only to close both sides of the stdin pipe in case the process is using that as its queue to stay alive?
Plus, I think the close stdout/err methods were added as signals to the upstream pipes that io is finished, rather than signals to the process that it should stop outputting things.

@helsaawy
Copy link
Contributor

@rumpl
I'm curious how you saw this situation arise, since if process.stdin is nil, then the underlying process shouldn't have a stdin handle to close.

@rumpl
Copy link
Contributor Author

rumpl commented Sep 14, 2023

@helsaawy We had this test failing.

It's running cat | echo "something", then we close stdin which makes cat exit and we should then see the output from echo. Without sending the close message cat would never receive an EOF and would never end.

@anmaxvl anmaxvl merged commit 27df1b9 into microsoft:main Sep 14, 2023
16 checks passed
anmaxvl pushed a commit to anmaxvl/hcsshim that referenced this pull request Sep 14, 2023
Send the modify request even if stdin is nil, let the process handle it

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
(cherry picked from commit 27df1b9)
@rumpl
Copy link
Contributor Author

rumpl commented Sep 14, 2023

Thanks for the merge!

What can we do to help get this backported to 0.11 and then get a new release

@neersighted
Copy link

neersighted commented Sep 14, 2023

Just noticed https://github.com/moby/moby/blob/20f96354699d20eeb4674d3944486b5d73c256b2/integration/container/exec_test.go#L19 -- is this potentially the missing CloseStdout in runhcs?

@neersighted
Copy link

Backport is open at #1900

anmaxvl pushed a commit to anmaxvl/hcsshim that referenced this pull request Sep 14, 2023
Send the modify request even if stdin is nil, let the process handle it

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
(cherry picked from commit 27df1b9)
Signed-off-by: Maksim An <maksiman@microsoft.com>
@rumpl
Copy link
Contributor Author

rumpl commented Sep 14, 2023

Just noticed https://github.com/moby/moby/blob/20f96354699d20eeb4674d3944486b5d73c256b2/integration/container/exec_test.go#L19 -- is this potentially the missing CloseStdout in runhcs?

We should definitely check if it fails still. A lot has happened in 2 years

@TBBle
Copy link
Contributor

TBBle commented Sep 16, 2023

Just noticed https://github.com/moby/moby/blob/20f96354699d20eeb4674d3944486b5d73c256b2/integration/container/exec_test.go#L19 -- is this potentially the missing CloseStdout in runhcs?

We should definitely check if it fails still. A lot has happened in 2 years

From memory there was some hcsshim/containerd io-hang issue like this that was never resolved. And last time this test came up, I said the same thing: moby/moby#41479 (comment)

I thought there had been some discussion in a containerd issue of a hcsshim-side fix being needed, but I can't actually find any evidence of the issue I'm thinking of in the hcsshim, containerd, or moby repos. >_< #1296 is the closest I can find, and I'm not sure it's related because it seems to be about spurious errors, not hangs.

I will note that TestExecWithCloseStdin is excluded on Windows/containerd test runs, but is also known-flakey (times out) for Windows non-containerd test runs. So it really just might be a "takes too long" case.

anmaxvl pushed a commit to anmaxvl/hcsshim that referenced this pull request Sep 20, 2023
Send the modify request even if stdin is nil, let the process handle it

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
(cherry picked from commit 27df1b9)
Signed-off-by: Maksim An <maksiman@microsoft.com>
anmaxvl pushed a commit to anmaxvl/hcsshim that referenced this pull request Sep 20, 2023
Send the modify request even if stdin is nil, let the process handle it

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
(cherry picked from commit 27df1b9)
Signed-off-by: Maksim An <maksiman@microsoft.com>
anmaxvl pushed a commit that referenced this pull request Sep 20, 2023
Send the modify request even if stdin is nil, let the process handle it

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
(cherry picked from commit 27df1b9)
Signed-off-by: Maksim An <maksiman@microsoft.com>
helsaawy pushed a commit to helsaawy/hcsshim that referenced this pull request Sep 27, 2023
Send the modify request even if stdin is nil, let the process handle it

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants