summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/compat/exec.go
diff options
context:
space:
mode:
authorEd Santiago <santiago@redhat.com>2020-08-27 12:57:33 -0600
committerGitHub <noreply@github.com>2020-08-27 12:57:33 -0600
commitb13af4537fea0647c029067c664f1e79e0a6c3e6 (patch)
tree98163cb6467b5742ed73e2dbbc8be77b884fbce2 /pkg/api/handlers/compat/exec.go
parent7d3cadcc54cbad9a109471f586c10541544bc7db (diff)
parent2ea9dac5e1d00b2820bd7156e3bea4b9fd98c1e6 (diff)
downloadpodman-b13af4537fea0647c029067c664f1e79e0a6c3e6.tar.gz
podman-b13af4537fea0647c029067c664f1e79e0a6c3e6.tar.bz2
podman-b13af4537fea0647c029067c664f1e79e0a6c3e6.zip
Merge pull request #7451 from mheon/fix_7195
Send HTTP Hijack headers after successful attach
Diffstat (limited to 'pkg/api/handlers/compat/exec.go')
-rw-r--r--pkg/api/handlers/compat/exec.go24
1 files changed, 17 insertions, 7 deletions
diff --git a/pkg/api/handlers/compat/exec.go b/pkg/api/handlers/compat/exec.go
index 7a62a2b58..1db950f85 100644
--- a/pkg/api/handlers/compat/exec.go
+++ b/pkg/api/handlers/compat/exec.go
@@ -10,6 +10,7 @@ import (
"github.com/containers/podman/v2/libpod/define"
"github.com/containers/podman/v2/pkg/api/handlers"
"github.com/containers/podman/v2/pkg/api/handlers/utils"
+ "github.com/containers/podman/v2/pkg/api/server/idletracker"
"github.com/containers/podman/v2/pkg/specgen/generate"
"github.com/gorilla/mux"
"github.com/pkg/errors"
@@ -173,15 +174,24 @@ func ExecStartHandler(w http.ResponseWriter, r *http.Request) {
return
}
- connection, buffer, err := AttachConnection(w, r)
- if err != nil {
- utils.InternalServerError(w, err)
- return
- }
- logrus.Debugf("Hijack for attach of container %s exec session %s successful", sessionCtr.ID(), sessionID)
+ idleTracker := r.Context().Value("idletracker").(*idletracker.IdleTracker)
+ hijackChan := make(chan bool, 1)
+
+ if err := sessionCtr.ExecHTTPStartAndAttach(sessionID, r, w, nil, nil, nil, hijackChan); err != nil {
+ hijackComplete := <-hijackChan
- if err := sessionCtr.ExecHTTPStartAndAttach(sessionID, connection, buffer, nil, nil, nil); err != nil {
logrus.Errorf("Error attaching to container %s exec session %s: %v", sessionCtr.ID(), sessionID, err)
+
+ if hijackComplete {
+ // We do need to tell the idle tracker that the
+ // connection has been closed, though. We can guarantee
+ // that is true after HTTPAttach exits.
+ idleTracker.TrackHijackedClosed()
+ } else {
+ // A hijack was not successfully completed. We need to
+ // report the error normally.
+ utils.InternalServerError(w, err)
+ }
}
logrus.Debugf("Attach for container %s exec session %s completed successfully", sessionCtr.ID(), sessionID)