summaryrefslogtreecommitdiff
path: root/pkg/bindings
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2021-10-05 11:13:49 +0200
committerPaul Holzinger <pholzing@redhat.com>2021-10-06 17:51:07 +0200
commitfbce7584d786ed99354a4b33a9c127abd673c3bb (patch)
tree2726f6e2df81a368323398330a786b3ae25afa64 /pkg/bindings
parent8bcc086b1b9d8aa0ef3bb08d37542adf9de26ac5 (diff)
downloadpodman-fbce7584d786ed99354a4b33a9c127abd673c3bb.tar.gz
podman-fbce7584d786ed99354a4b33a9c127abd673c3bb.tar.bz2
podman-fbce7584d786ed99354a4b33a9c127abd673c3bb.zip
libpod: fix race when closing STDIN
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 #11856 Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'pkg/bindings')
-rw-r--r--pkg/bindings/containers/attach.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/pkg/bindings/containers/attach.go b/pkg/bindings/containers/attach.go
index abf58aaf9..c5f54c1af 100644
--- a/pkg/bindings/containers/attach.go
+++ b/pkg/bindings/containers/attach.go
@@ -157,24 +157,24 @@ func Attach(ctx context.Context, nameOrID string, stdin io.Reader, stdout io.Wri
}
stdoutChan := make(chan error)
- stdinChan := make(chan error)
+ stdinChan := make(chan error, 1) //stdin channel should not block
if isSet.stdin {
go func() {
logrus.Debugf("Copying STDIN to socket")
_, err := utils.CopyDetachable(socket, stdin, detachKeysInBytes)
-
if err != nil && err != define.ErrDetach {
logrus.Errorf("Failed to write input to service: %v", err)
}
- stdinChan <- err
-
- if closeWrite, ok := socket.(CloseWriter); ok {
- if err := closeWrite.CloseWrite(); err != nil {
- logrus.Warnf("Failed to close STDIN for writing: %v", err)
+ if err == nil {
+ if closeWrite, ok := socket.(CloseWriter); ok {
+ if err := closeWrite.CloseWrite(); err != nil {
+ logrus.Warnf("Failed to close STDIN for writing: %v", err)
+ }
}
}
+ stdinChan <- err
}()
}