summaryrefslogtreecommitdiff
path: root/pkg/api/server/idletracker/idletracker.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-09-30 14:37:31 +0000
committerGitHub <noreply@github.com>2020-09-30 14:37:31 +0000
commitfb43e8c6a44e12bca3bbd0480b3fd75134704012 (patch)
tree904f8cb1d5555c5dcde29f3404caaf37be8a103d /pkg/api/server/idletracker/idletracker.go
parent4d57313449a7f7c86697ad830816f5c1e73c05ca (diff)
parentf03d470349731b5119d7b49e620d7a9bb2cbff38 (diff)
downloadpodman-fb43e8c6a44e12bca3bbd0480b3fd75134704012.tar.gz
podman-fb43e8c6a44e12bca3bbd0480b3fd75134704012.tar.bz2
podman-fb43e8c6a44e12bca3bbd0480b3fd75134704012.zip
Merge pull request #7833 from jwhonce/issues/7826
Refactor IdleTracker to handle StateIdle transitions
Diffstat (limited to 'pkg/api/server/idletracker/idletracker.go')
-rw-r--r--pkg/api/server/idletracker/idletracker.go74
1 files changed, 0 insertions, 74 deletions
diff --git a/pkg/api/server/idletracker/idletracker.go b/pkg/api/server/idletracker/idletracker.go
deleted file mode 100644
index 1ee905a99..000000000
--- a/pkg/api/server/idletracker/idletracker.go
+++ /dev/null
@@ -1,74 +0,0 @@
-package idletracker
-
-import (
- "net"
- "net/http"
- "sync"
- "time"
-
- "github.com/sirupsen/logrus"
-)
-
-type IdleTracker struct {
- http map[net.Conn]struct{}
- hijacked int
- total int
- mux sync.Mutex
- timer *time.Timer
- Duration time.Duration
-}
-
-func NewIdleTracker(idle time.Duration) *IdleTracker {
- return &IdleTracker{
- http: make(map[net.Conn]struct{}),
- Duration: idle,
- timer: time.NewTimer(idle),
- }
-}
-
-func (t *IdleTracker) ConnState(conn net.Conn, state http.ConnState) {
- t.mux.Lock()
- defer t.mux.Unlock()
-
- oldActive := t.ActiveConnections()
- logrus.Debugf("IdleTracker %p:%v %d/%d connection(s)", conn, state, oldActive, t.TotalConnections())
- switch state {
- case http.StateNew, http.StateActive:
- t.http[conn] = struct{}{}
- // stop the timer if we transitioned from idle
- if oldActive == 0 {
- t.timer.Stop()
- }
- t.total++
- case http.StateHijacked:
- // hijacked connections are handled elsewhere
- delete(t.http, conn)
- t.hijacked++
- case http.StateIdle, http.StateClosed:
- delete(t.http, conn)
- // Restart the timer if we've become idle
- if oldActive > 0 && len(t.http) == 0 {
- t.timer.Stop()
- t.timer.Reset(t.Duration)
- }
- }
-}
-
-func (t *IdleTracker) TrackHijackedClosed() {
- t.mux.Lock()
- defer t.mux.Unlock()
-
- t.hijacked--
-}
-
-func (t *IdleTracker) ActiveConnections() int {
- return len(t.http) + t.hijacked
-}
-
-func (t *IdleTracker) TotalConnections() int {
- return t.total
-}
-
-func (t *IdleTracker) Done() <-chan time.Time {
- return t.timer.C
-}