From 70760b187f8bfe3934f1f35d0f8ea1624b144e60 Mon Sep 17 00:00:00 2001 From: Seebs Date: Mon, 21 Mar 2022 14:08:43 -0500 Subject: [PATCH] prevent concurrent map writes in openField Prior to this, we locked the index-wide i.mu around writes to i.fields. But now the entire open process is holding that lock, so we couldn't lock it here (that'd deadlock) and didn't think we needed to (because it was held). But in fact that means that multiple fields being opened at once can concurrently write to the map. Conveniently, we *already* pass a shared mutex into openField() to prevent exactly this sort of problem; we just need to actually use it when doing the write. --- index.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.go b/index.go index 5f6e7190c..6108d514f 100644 --- a/index.go +++ b/index.go @@ -341,7 +341,9 @@ func (i *Index) openField(mu *sync.Mutex, cfm *CreateFieldMessage, file string) } i.holder.Logger.Debugf("add field to index.fields: %s", file) + mu.Lock() i.fields[fld.Name()] = fld + mu.Unlock() return fld, nil }