From bbe39af99f0ab5aa54959886f1d5b83bcf588f23 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 6 Mar 2024 12:36:34 +0000 Subject: [PATCH] tsdb: zero out Labels and memSeries pointers in pool (#13712) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * tsdb: zero out Labels and memSeries pointers in pool So that the garbage-collector doesn't see this memory as still in use. Signed-off-by: Bryan Boreham --------- Signed-off-by: Bryan Boreham Signed-off-by: Björn Rabenstein Co-authored-by: Björn Rabenstein --- tsdb/head_append.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tsdb/head_append.go b/tsdb/head_append.go index a0bf98716..6342a19d4 100644 --- a/tsdb/head_append.go +++ b/tsdb/head_append.go @@ -229,6 +229,9 @@ func (h *Head) putExemplarBuffer(b []exemplarWithSeriesRef) { if b == nil { return } + for i := range b { // Zero out to avoid retaining label data. + b[i].exemplar.Labels = labels.EmptyLabels() + } h.exemplarsPool.Put(b[:0]) } @@ -278,6 +281,9 @@ func (h *Head) getSeriesBuffer() []*memSeries { } func (h *Head) putSeriesBuffer(b []*memSeries) { + for i := range b { // Zero out to avoid retaining data. + b[i] = nil + } h.seriesPool.Put(b[:0]) }