Skip to content

Commit d3ffbb6

Browse files
authored
Only Reset non-nil fields. (#2558)
Protobuf message's `Reset` assumes non-nil callers, so check to make sure we don't cause a panic if the cgroup stats call didn't initialize those fields. Signed-off-by: Hamza El-Saawy <[email protected]>
1 parent 9fb15b4 commit d3ffbb6

File tree

1 file changed

+12
-3
lines changed
  • internal/guest/runtime/hcsv2

1 file changed

+12
-3
lines changed

internal/guest/runtime/hcsv2/uvm.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,10 +1027,19 @@ func (h *Host) GetProperties(ctx context.Context, containerID string, query prot
10271027
// zero out [Blkio] sections, since:
10281028
// 1. (Az)CRI (currently) only looks at the CPU and memory sections; and
10291029
// 2. it can get very large for containers with many layers
1030-
cgroupMetrics.Blkio.Reset()
1030+
if cgroupMetrics.GetBlkio() != nil {
1031+
cgroupMetrics.Blkio.Reset()
1032+
}
10311033
// also preemptively zero out [Rdma] and [Network], since they could also grow untenable large
1032-
cgroupMetrics.Rdma.Reset()
1033-
cgroupMetrics.Network = []*cgroup1stats.NetworkStat{}
1034+
if cgroupMetrics.GetRdma() != nil {
1035+
cgroupMetrics.Rdma.Reset()
1036+
}
1037+
if len(cgroupMetrics.GetNetwork()) > 0 {
1038+
cgroupMetrics.Network = []*cgroup1stats.NetworkStat{}
1039+
}
1040+
if logrus.IsLevelEnabled(logrus.TraceLevel) {
1041+
log.G(ctx).WithField("stats", log.Format(ctx, cgroupMetrics)).Trace("queried cgroup statistics")
1042+
}
10341043
properties.Metrics = cgroupMetrics
10351044
default:
10361045
log.G(ctx).WithField("propertyType", requestedProperty).Warn("unknown or empty property type")

0 commit comments

Comments
 (0)