From 3c7b7761ceafc24f9fa42e5f08178d8c644d9017 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Wed, 15 Jan 2020 11:41:38 +0100 Subject: v2: stats: do not ignore errors We must check all errors and handle them properly. Otherwise, we can run into nil dereferences ultimately killing the service. Signed-off-by: Valentin Rothberg --- pkg/api/handlers/generic/containers_stats.go | 37 +++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'pkg/api/handlers/generic') diff --git a/pkg/api/handlers/generic/containers_stats.go b/pkg/api/handlers/generic/containers_stats.go index 538fc6f21..eb9cfca4a 100644 --- a/pkg/api/handlers/generic/containers_stats.go +++ b/pkg/api/handlers/generic/containers_stats.go @@ -81,19 +81,44 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) { time.Sleep(DefaultStatsPeriod) } - cgroupPath, _ := ctnr.CGroupPath() - cgroup, _ := cgroups.Load(cgroupPath) + cgroupPath, err := ctnr.CGroupPath() + if err != nil { + utils.InternalServerError(w, err) + return + } + + cgroup, err := cgroups.Load(cgroupPath) + if err != nil { + utils.InternalServerError(w, err) + return + } for ok := true; ok; ok = query.Stream { - state, _ := ctnr.State() + state, err := ctnr.State() + if err != nil { + utils.InternalServerError(w, err) + return + } if state != define.ContainerStateRunning { time.Sleep(10 * time.Second) continue } - stats, _ := ctnr.GetContainerStats(stats) - cgroupStat, _ := cgroup.Stat() - inspect, _ := ctnr.Inspect(false) + stats, err := ctnr.GetContainerStats(stats) + if err != nil { + utils.InternalServerError(w, err) + return + } + cgroupStat, err := cgroup.Stat() + if err != nil { + utils.InternalServerError(w, err) + return + } + inspect, err := ctnr.Inspect(false) + if err != nil { + utils.InternalServerError(w, err) + return + } net := make(map[string]docker.NetworkStats) net[inspect.NetworkSettings.EndpointID] = docker.NetworkStats{ -- cgit v1.2.3-54-g00ecf