From 9c417aa71045e36d9fad66e1e77c1d942cbacc17 Mon Sep 17 00:00:00 2001 From: Oleg Zaytsev Date: Wed, 25 Sep 2024 14:08:50 +0200 Subject: [PATCH] Fix deadlock with empty MemPostings Signed-off-by: Oleg Zaytsev --- tsdb/index/postings.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tsdb/index/postings.go b/tsdb/index/postings.go index 25780e4ad..3164d8c2f 100644 --- a/tsdb/index/postings.go +++ b/tsdb/index/postings.go @@ -295,7 +295,8 @@ func (p *MemPostings) Delete(deleted map[storage.SeriesRef]struct{}, affected ma defer p.mtx.Unlock() // Deleting label names mutates p.m map, so it should be done from a single goroutine after nobody else is reading it. - deleteLabelNames := make(chan string, len(p.m)) + // Adding +1 to length to account for allPostingsKey processing when MemPostings is empty. + deleteLabelNames := make(chan string, len(p.m)+1) process := func(l labels.Label) { orig := p.m[l.Name][l.Value]