-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
libpod: fix race when closing STDIN #11864
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice catch!
@containers/podman-maintainers PTAL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just one concern should we acquire mutex and then try so Close
with error ? Correct me if i am wrong we will be all missing errors which are being created while copying buffers and silently closing channel.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: flouthoc, 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 |
Looks like at least one of those |
Removing these entirely breaks scenarios where STDIN closes immediately again - Podman will hang forever waiting for input that never comes. It begins to sound like we need a dedicated "Closed" bool somewhere? |
How about I keep CloseWrite but do not log the error? |
@Luap99 how about we abstract the output from channel into a struct ? and we can use channel to relay error back if any with the actual result and we can process error at caller level Something like type Result struct {
ActualData string
Error error
}
ch := make(chan Result) |
@Luap99 Can we catch and ignore duplicate close errors and print the others? |
I pushed a new version which closes STDIN in same goroutine so the race should be gone. |
LGTM |
libpod/oci_attach_linux.go
Outdated
var err error | ||
select { | ||
case err = <-receiveStdoutError: | ||
return err | ||
case err = <-stdinDone: | ||
// copy stdin is done, close it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semantics here aren't a precise match, we need to only do the one-sided close if err
is nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Also added another fix for podman-remote run where stdin was never closed.
There is a race where `conn.Close()` was called before `conn.CloseWrite()`. In this case `CloseWrite` will fail and an useless error is printed. To fix this we move the the `CloseWrite()` call to the same goroutine to remove the race. This ensures that `CloseWrite()` is called before `Close()` and never afterwards. Also fixed podman-remote run where the STDIN was never was closed. This is causing flakes in CI testing. [NO TESTS NEEDED] Fixes containers#11856 Signed-off-by: Paul Holzinger <[email protected]>
LGTM |
/lgtm |
What this PR does / why we need it:
There is a race where
conn.Close()
was called beforeconn.CloseWrite()
.In this case
CloseWrite
will fail and an useless error is printed. Tofix this we move the the
CloseWrite()
call to the same goroutine toremove the race. This ensures that
CloseWrite()
is called beforeClose()
and never afterwards.This is causing flakes in CI testing.
How to verify it
not possible, CI flake
Which issue(s) this PR fixes:
Fixes #11856
Special notes for your reviewer: