From 06aceb5432d460781e513f167bc381c197bd1965 Mon Sep 17 00:00:00 2001 From: Hamza El-Saawy Date: Mon, 10 Nov 2025 16:54:58 -0500 Subject: [PATCH] Only `Reset` non-nil fields. 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 --- internal/guest/runtime/hcsv2/uvm.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/internal/guest/runtime/hcsv2/uvm.go b/internal/guest/runtime/hcsv2/uvm.go index 7b53536100..316c843d4f 100644 --- a/internal/guest/runtime/hcsv2/uvm.go +++ b/internal/guest/runtime/hcsv2/uvm.go @@ -1027,10 +1027,19 @@ func (h *Host) GetProperties(ctx context.Context, containerID string, query prot // zero out [Blkio] sections, since: // 1. (Az)CRI (currently) only looks at the CPU and memory sections; and // 2. it can get very large for containers with many layers - cgroupMetrics.Blkio.Reset() + if cgroupMetrics.GetBlkio() != nil { + cgroupMetrics.Blkio.Reset() + } // also preemptively zero out [Rdma] and [Network], since they could also grow untenable large - cgroupMetrics.Rdma.Reset() - cgroupMetrics.Network = []*cgroup1stats.NetworkStat{} + if cgroupMetrics.GetRdma() != nil { + cgroupMetrics.Rdma.Reset() + } + if len(cgroupMetrics.GetNetwork()) > 0 { + cgroupMetrics.Network = []*cgroup1stats.NetworkStat{} + } + if logrus.IsLevelEnabled(logrus.TraceLevel) { + log.G(ctx).WithField("stats", log.Format(ctx, cgroupMetrics)).Trace("queried cgroup statistics") + } properties.Metrics = cgroupMetrics default: log.G(ctx).WithField("propertyType", requestedProperty).Warn("unknown or empty property type")