From 8cc31b128b7c00009e526f65b8eb81ea89ddefe9 Mon Sep 17 00:00:00 2001 From: Matej Gera Date: Tue, 12 Jul 2022 14:06:26 +0200 Subject: [PATCH] Fix data race in label set copying Signed-off-by: Matej Gera --- pkg/receive/writer.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/receive/writer.go b/pkg/receive/writer.go index 90bb2897c4c..f76cd44ee41 100644 --- a/pkg/receive/writer.go +++ b/pkg/receive/writer.go @@ -77,8 +77,11 @@ func (r *Writer) Write(ctx context.Context, tenantID string, wreq *prompb.WriteR if ref == 0 { // If not, copy labels, as TSDB will hold those strings long term. Given no // copy unmarshal we don't want to keep memory for whole protobuf, only for labels. - labelpb.ReAllocZLabelsStrings(&t.Labels) - lset = labelpb.ZLabelsToPromLabels(t.Labels) + lsetCopy := make([]labelpb.ZLabel, len(t.Labels)) + copy(lsetCopy, t.Labels) + + labelpb.ReAllocZLabelsStrings(&lsetCopy) + lset = labelpb.ZLabelsToPromLabels(lsetCopy) } // Append as many valid samples as possible, but keep track of the errors.