From 9a3d30f8ead5de39a14eea8ef7a7897a61c6fa30 Mon Sep 17 00:00:00 2001 From: Francisco Javier Honduvilla Coto Date: Thu, 21 Apr 2022 15:52:59 +0100 Subject: [PATCH] profiler: Fix index out of range ``` panic: runtime error: index out of range [0] with length 0 goroutine 82 [running]: github.com/parca-dev/parca-agent/pkg/profiler.(*CgroupProfiler).writeProfile(0x2040000bb8c0, {0x2790780, 0x204000846120}, 0x3f3d360?) github.com/parca-dev/parca-agent/pkg/profiler/profiler.go:772 +0xa24 github.com/parca-dev/parca-agent/pkg/profiler.(*CgroupProfiler).profileLoop(0x2040000bb8c0, {0x2790780, 0x204000846120}, {0x0?, 0x23f4010?, 0x3f0bb80?}) github.com/parca-dev/parca-agent/pkg/profiler/profiler.go:521 +0xe44 github.com/parca-dev/parca-agent/pkg/profiler.(*CgroupProfiler).Run(0x2040000bb8c0, {0x2790780, 0x20400080fe00}) github.com/parca-dev/parca-agent/pkg/profiler/profiler.go:377 +0xe40 github.com/parca-dev/parca-agent/pkg/target.(*ProfilerPool).Sync.func1() github.com/parca-dev/parca-agent/pkg/target/profiler_pool.go:155 +0x40 created by github.com/parca-dev/parca-agent/pkg/target.(*ProfilerPool).Sync github.com/parca-dev/parca-agent/pkg/target/profiler_pool.go:154 +0x43c ``` --- pkg/profiler/profiler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/profiler/profiler.go b/pkg/profiler/profiler.go index 4e119b7f6..5d49fb171 100644 --- a/pkg/profiler/profiler.go +++ b/pkg/profiler/profiler.go @@ -765,10 +765,10 @@ func (p *CgroupProfiler) writeProfile(ctx context.Context, prof *profile.Profile i = 0 ) for key, value := range p.Labels() { - labelOldFormat[i] = &profilestorepb.Label{ + labelOldFormat = append(labelOldFormat, &profilestorepb.Label{ Name: string(key), Value: string(value), - } + }) i++ }