Skip to content

Commit

Permalink
Merge pull request #7762 from mheon/maybe_this_works
Browse files Browse the repository at this point in the history
HTTP Attach: Wait until both STDIN and STDOUT finish
  • Loading branch information
openshift-merge-robot authored Sep 24, 2020
2 parents 684cde8 + 00cca40 commit 90c2cc6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
27 changes: 16 additions & 11 deletions libpod/oci_conmon_exec_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,6 @@ func attachExecHTTP(c *Container, sessionID string, r *http.Request, w http.Resp
}
}()

// Make a channel to pass errors back
errChan := make(chan error)

attachStdout := true
attachStderr := true
attachStdin := true
Expand Down Expand Up @@ -580,13 +577,16 @@ func attachExecHTTP(c *Container, sessionID string, r *http.Request, w http.Resp
hijackWriteErrorAndClose(deferredErr, c.ID(), isTerminal, httpCon, httpBuf)
}()

stdoutChan := make(chan error)
stdinChan := make(chan error)

// Next, STDIN. Avoid entirely if attachStdin unset.
if attachStdin {
go func() {
logrus.Debugf("Beginning STDIN copy")
_, err := utils.CopyDetachable(conn, httpBuf, detachKeys)
logrus.Debugf("STDIN copy completed")
errChan <- err
stdinChan <- err
}()
}

Expand All @@ -613,19 +613,24 @@ func attachExecHTTP(c *Container, sessionID string, r *http.Request, w http.Resp
logrus.Debugf("Performing non-terminal HTTP attach for container %s", c.ID())
err = httpAttachNonTerminalCopy(conn, httpBuf, c.ID(), attachStdin, attachStdout, attachStderr)
}
errChan <- err
stdoutChan <- err
logrus.Debugf("STDOUT/ERR copy completed")
}()

if cancel != nil {
for {
select {
case err := <-errChan:
return err
case err := <-stdoutChan:
if err != nil {
return err
}

return nil
case err := <-stdinChan:
if err != nil {
return err
}
case <-cancel:
return nil
}
} else {
var connErr error = <-errChan
return connErr
}
}
27 changes: 16 additions & 11 deletions libpod/oci_conmon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,6 @@ func (r *ConmonOCIRuntime) HTTPAttach(ctr *Container, req *http.Request, w http.
return err
}

// Make a channel to pass errors back
errChan := make(chan error)

attachStdout := true
attachStderr := true
attachStdin := true
Expand Down Expand Up @@ -672,6 +669,9 @@ func (r *ConmonOCIRuntime) HTTPAttach(ctr *Container, req *http.Request, w http.

logrus.Debugf("Forwarding attach output for container %s", ctr.ID())

stdoutChan := make(chan error)
stdinChan := make(chan error)

// Handle STDOUT/STDERR
go func() {
var err error
Expand All @@ -690,28 +690,33 @@ func (r *ConmonOCIRuntime) HTTPAttach(ctr *Container, req *http.Request, w http.
logrus.Debugf("Performing non-terminal HTTP attach for container %s", ctr.ID())
err = httpAttachNonTerminalCopy(conn, httpBuf, ctr.ID(), attachStdin, attachStdout, attachStderr)
}
errChan <- err
stdoutChan <- err
logrus.Debugf("STDOUT/ERR copy completed")
}()
// Next, STDIN. Avoid entirely if attachStdin unset.
if attachStdin {
go func() {
_, err := utils.CopyDetachable(conn, httpBuf, detach)
logrus.Debugf("STDIN copy completed")
errChan <- err
stdinChan <- err
}()
}

if cancel != nil {
for {
select {
case err := <-errChan:
return err
case err := <-stdoutChan:
if err != nil {
return err
}

return nil
case err := <-stdinChan:
if err != nil {
return err
}
case <-cancel:
return nil
}
} else {
var connErr error = <-errChan
return connErr
}
}

Expand Down

0 comments on commit 90c2cc6

Please sign in to comment.