From 36f93649efbd2a3bd7954d8c6f2758507229bda9 Mon Sep 17 00:00:00 2001 From: vyzo Date: Sun, 4 Jul 2021 10:10:37 +0300 Subject: [PATCH] fix panic from concurrent map writes in txnRefs --- blockstore/splitstore/splitstore.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/blockstore/splitstore/splitstore.go b/blockstore/splitstore/splitstore.go index 669277abe..ced493ed9 100644 --- a/blockstore/splitstore/splitstore.go +++ b/blockstore/splitstore/splitstore.go @@ -145,11 +145,12 @@ type SplitStore struct { // protection for concurrent read/writes during compaction txnLk sync.RWMutex + txnActive bool txnEnv MarkSetEnv txnProtect MarkSet txnMarkSet MarkSet + txnRefsMx sync.Mutex txnRefs map[cid.Cid]struct{} - txnActive bool } var _ bstore.Blockstore = (*SplitStore)(nil) @@ -594,7 +595,9 @@ func (s *SplitStore) trackTxnRef(c cid.Cid, recursive bool) error { if s.txnRefs != nil { // we haven't finished marking yet, so track the reference + s.txnRefsMx.Lock() s.txnRefs[c] = struct{}{} + s.txnRefsMx.Unlock() return nil }