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.
This commit is contained in:
Seebs 2022-03-21 14:08:43 -05:00
parent a9b56b055e
commit 70760b187f

View file

@ -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
}