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.