Skip to content

Commit

Permalink
v2: stats: do not ignore errors
Browse files Browse the repository at this point in the history
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 <rothberg@redhat.com>
  • Loading branch information
vrothberg committed Jan 15, 2020
1 parent a1ff93b commit 3c7b776
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions pkg/api/handlers/generic/containers_stats.go
Expand Up @@ -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{
Expand Down

0 comments on commit 3c7b776

Please sign in to comment.