From 625a9d81f15504071b67f8ae3c22e3686ba3ee12 Mon Sep 17 00:00:00 2001 From: Manish R Jain <manish@dgraph.io> Date: Fri, 10 Feb 2017 13:36:22 +1100 Subject: [PATCH] Bug Fix: Set the water reference before putting list in map, otherwise it can be nil causing panic. --- posting/lists.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/posting/lists.go b/posting/lists.go index 59544959..01d9d31b 100644 --- a/posting/lists.go +++ b/posting/lists.go @@ -368,7 +368,11 @@ func GetOrCreate(key []byte, group uint32) (rlist *List, decr func()) { return lp, lp.decr } + // Any initialization for l must be done before PutIfMissing. Once it's added + // to the map, any other goroutine can retrieve it. l := getNew(key, pstore) // This retrieves a new *List and sets refcount to 1. + l.water = marks.Get(group) + lp = lhmap.PutIfMissing(fp, l) // We are always going to return lp to caller, whether it is l or not. So, let's // increment its reference counter. @@ -378,7 +382,6 @@ func GetOrCreate(key []byte, group uint32) (rlist *List, decr func()) { // Undo the increment in getNew() call above. l.decr() } - lp.water = marks.Get(group) pk := x.Parse(key) // This replaces "TokensTable". The idea is that we want to quickly add the -- GitLab