From 30d0ea59d7ac7ddb1190d7a2848d0b5e34f9aec0 Mon Sep 17 00:00:00 2001 From: Brian Brazil Date: Thu, 16 May 2019 14:36:44 +0100 Subject: [PATCH] Don't crash on an unknown tombstone ref. (#604) Fixes https://github.com/prometheus/prometheus/issues/5562 Signed-off-by: Brian Brazil --- head.go | 4 ++++ head_test.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/head.go b/head.go index 30cbe61e2..92619a640 100644 --- a/head.go +++ b/head.go @@ -421,6 +421,10 @@ func (h *Head) loadWAL(r *wal.Reader) error { if itv.Maxt < h.minValidTime { continue } + if m := h.series.getByID(s.ref); m == nil { + unknownRefs++ + continue + } allStones.addInterval(s.ref, itv) } } diff --git a/head_test.go b/head_test.go index 9e78b6b62..79092dd5c 100644 --- a/head_test.go +++ b/head_test.go @@ -114,6 +114,9 @@ func TestHead_ReadWAL(t *testing.T) { {Ref: 10, T: 101, V: 5}, {Ref: 50, T: 101, V: 6}, }, + []Stone{ + {ref: 0, intervals: []Interval{{Mint: 99, Maxt: 101}}}, + }, } dir, err := ioutil.TempDir("", "test_read_wal") testutil.Ok(t, err)