From 0253f6fe05e8aa5d5382ef7a05d5c956a11fac94 Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Tue, 29 May 2018 09:39:51 -0700 Subject: [PATCH] fix(tsdb/engine/tsm1): Fix panic when closing cursor multiple times Fixes #9909 --- tsdb/engine/tsm1/batch_cursor.gen.go | 30 +++++++++++++++-------- tsdb/engine/tsm1/batch_cursor.gen.go.tmpl | 6 +++-- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/tsdb/engine/tsm1/batch_cursor.gen.go b/tsdb/engine/tsm1/batch_cursor.gen.go index f9da17ed152..c3dca83db07 100644 --- a/tsdb/engine/tsm1/batch_cursor.gen.go +++ b/tsdb/engine/tsm1/batch_cursor.gen.go @@ -99,8 +99,10 @@ func (c *floatAscendingBatchCursor) Err() error { return nil } // close closes the cursor and any dependent cursors. func (c *floatAscendingBatchCursor) Close() { - c.tsm.keyCursor.Close() - c.tsm.keyCursor = nil + if c.tsm.keyCursor != nil { + c.tsm.keyCursor.Close() + c.tsm.keyCursor = nil + } c.cache.values = nil c.tsm.values = nil } @@ -398,8 +400,10 @@ func (c *integerAscendingBatchCursor) Err() error { return nil } // close closes the cursor and any dependent cursors. func (c *integerAscendingBatchCursor) Close() { - c.tsm.keyCursor.Close() - c.tsm.keyCursor = nil + if c.tsm.keyCursor != nil { + c.tsm.keyCursor.Close() + c.tsm.keyCursor = nil + } c.cache.values = nil c.tsm.values = nil } @@ -697,8 +701,10 @@ func (c *unsignedAscendingBatchCursor) Err() error { return nil } // close closes the cursor and any dependent cursors. func (c *unsignedAscendingBatchCursor) Close() { - c.tsm.keyCursor.Close() - c.tsm.keyCursor = nil + if c.tsm.keyCursor != nil { + c.tsm.keyCursor.Close() + c.tsm.keyCursor = nil + } c.cache.values = nil c.tsm.values = nil } @@ -996,8 +1002,10 @@ func (c *stringAscendingBatchCursor) Err() error { return nil } // close closes the cursor and any dependent cursors. func (c *stringAscendingBatchCursor) Close() { - c.tsm.keyCursor.Close() - c.tsm.keyCursor = nil + if c.tsm.keyCursor != nil { + c.tsm.keyCursor.Close() + c.tsm.keyCursor = nil + } c.cache.values = nil c.tsm.values = nil } @@ -1295,8 +1303,10 @@ func (c *booleanAscendingBatchCursor) Err() error { return nil } // close closes the cursor and any dependent cursors. func (c *booleanAscendingBatchCursor) Close() { - c.tsm.keyCursor.Close() - c.tsm.keyCursor = nil + if c.tsm.keyCursor != nil { + c.tsm.keyCursor.Close() + c.tsm.keyCursor = nil + } c.cache.values = nil c.tsm.values = nil } diff --git a/tsdb/engine/tsm1/batch_cursor.gen.go.tmpl b/tsdb/engine/tsm1/batch_cursor.gen.go.tmpl index a10c082dd0a..457af10eb2a 100644 --- a/tsdb/engine/tsm1/batch_cursor.gen.go.tmpl +++ b/tsdb/engine/tsm1/batch_cursor.gen.go.tmpl @@ -67,8 +67,10 @@ func (c *{{.name}}AscendingBatchCursor) Err() error { return nil } // close closes the cursor and any dependent cursors. func (c *{{.name}}AscendingBatchCursor) Close() { - c.tsm.keyCursor.Close() - c.tsm.keyCursor = nil + if c.tsm.keyCursor != nil { + c.tsm.keyCursor.Close() + c.tsm.keyCursor = nil + } c.cache.values = nil c.tsm.values = nil }