summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/compat
diff options
context:
space:
mode:
authorKorhonen Sami (Samlink) <k847259@ubuntu.saminet.fi>2020-07-09 21:42:27 +0300
committerKorhonen Sami (Samlink) <k847259@ubuntu.saminet.fi>2020-07-09 22:17:27 +0300
commit324a02ec609f24aaba923a96266657d125228033 (patch)
treea5a61e0709d2c164734778b9d6248de4c86ce7c7 /pkg/api/handlers/compat
parent8b07ae32787ce61717b94aa7e5cc6ee02f4efa1d (diff)
downloadpodman-324a02ec609f24aaba923a96266657d125228033.tar.gz
podman-324a02ec609f24aaba923a96266657d125228033.tar.bz2
podman-324a02ec609f24aaba923a96266657d125228033.zip
Fix: Correct connection counters for hijacked connections
This patch fixes connection counters for v2 endpoints Idletracker was moved to a new package to prevent package cycle. Hijacking code still remains in wrong place and should be moved later to isolated package Signed-off-by: Sami Korhonen <skorhone@gmail.com>
Diffstat (limited to 'pkg/api/handlers/compat')
-rw-r--r--pkg/api/handlers/compat/containers_attach.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/pkg/api/handlers/compat/containers_attach.go b/pkg/api/handlers/compat/containers_attach.go
index 724b54ac4..71586fca4 100644
--- a/pkg/api/handlers/compat/containers_attach.go
+++ b/pkg/api/handlers/compat/containers_attach.go
@@ -11,6 +11,7 @@ import (
"github.com/containers/libpod/v2/libpod"
"github.com/containers/libpod/v2/libpod/define"
"github.com/containers/libpod/v2/pkg/api/handlers/utils"
+ "github.com/containers/libpod/v2/pkg/api/server/idletracker"
"github.com/gorilla/schema"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -115,7 +116,21 @@ func AttachContainer(w http.ResponseWriter, r *http.Request) {
logrus.Debugf("Attach for container %s completed successfully", ctr.ID())
}
+type HijackedConnection struct {
+ net.Conn // Connection
+ idleTracker *idletracker.IdleTracker // Connection tracker
+}
+
+func (c HijackedConnection) Close() error {
+ logrus.Debugf("Hijacked connection closed")
+
+ c.idleTracker.TrackHijackedClosed()
+ return c.Conn.Close()
+}
+
func AttachConnection(w http.ResponseWriter, r *http.Request) (net.Conn, *bufio.ReadWriter, error) {
+ idleTracker := r.Context().Value("idletracker").(*idletracker.IdleTracker)
+
// Hijack the connection
hijacker, ok := w.(http.Hijacker)
if !ok {
@@ -126,10 +141,14 @@ func AttachConnection(w http.ResponseWriter, r *http.Request) (net.Conn, *bufio.
if err != nil {
return nil, nil, errors.Wrapf(err, "error hijacking connection")
}
+ trackedConnection := HijackedConnection{
+ Conn: connection,
+ idleTracker: idleTracker,
+ }
- WriteAttachHeaders(r, connection)
+ WriteAttachHeaders(r, trackedConnection)
- return connection, buffer, nil
+ return trackedConnection, buffer, nil
}
func WriteAttachHeaders(r *http.Request, connection io.Writer) {