summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2020-09-18 13:56:31 +0200
committerValentin Rothberg <rothberg@redhat.com>2020-09-18 14:07:18 +0200
commitae0e4dfd75326c05bfe285c154d2e530a6adc657 (patch)
tree39197caf07d9f788139247b0812a7a11fa9707d4 /pkg
parentc6410076b0a5ed2831868b1b0bf99571cd38c4ab (diff)
downloadpodman-ae0e4dfd75326c05bfe285c154d2e530a6adc657.tar.gz
podman-ae0e4dfd75326c05bfe285c154d2e530a6adc657.tar.bz2
podman-ae0e4dfd75326c05bfe285c154d2e530a6adc657.zip
stats: detect closed client connection
Detect closed client connections and stop streaming. Fixes: #7521 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/api/handlers/compat/containers_stats.go17
1 files changed, 12 insertions, 5 deletions
diff --git a/pkg/api/handlers/compat/containers_stats.go b/pkg/api/handlers/compat/containers_stats.go
index d7970741d..d3f9b7c41 100644
--- a/pkg/api/handlers/compat/containers_stats.go
+++ b/pkg/api/handlers/compat/containers_stats.go
@@ -86,7 +86,12 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) {
coder := json.NewEncoder(w)
coder.SetEscapeHTML(true)
- for ok := true; ok; ok = query.Stream {
+streamLabel: // A label to flatten the scope
+ select {
+ case <-r.Context().Done():
+ logrus.Debugf("Client connection (container stats) cancelled")
+
+ default:
// Container stats
stats, err := ctnr.GetContainerStats(stats)
if err != nil {
@@ -194,6 +199,10 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) {
flusher.Flush()
}
+ if !query.Stream {
+ return
+ }
+
preRead = s.Read
bits, err := json.Marshal(s.CPUStats)
if err != nil {
@@ -203,10 +212,8 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) {
logrus.Errorf("Unable to unmarshal previous stats: %q", err)
}
- // Only sleep when we're streaming.
- if query.Stream {
- time.Sleep(DefaultStatsPeriod)
- }
+ time.Sleep(DefaultStatsPeriod)
+ goto streamLabel
}
}