From 877dfbe992576394c1ff4f8cf638814013a2d6dd Mon Sep 17 00:00:00 2001 From: vyzo Date: Mon, 31 Jan 2022 19:21:03 +0200 Subject: [PATCH] hold the lock in the second protect call --- blockstore/splitstore/splitstore_compact.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/blockstore/splitstore/splitstore_compact.go b/blockstore/splitstore/splitstore_compact.go index af5a425e9..1a2956655 100644 --- a/blockstore/splitstore/splitstore_compact.go +++ b/blockstore/splitstore/splitstore_compact.go @@ -721,10 +721,13 @@ func (s *SplitStore) beginCriticalSection(markSet MarkSet) error { } s.txnLk.Lock() - s.txnMarkSet = markSet - s.txnLk.Unlock() + defer s.txnLk.Unlock() - // and do it again to mark references that might have been created in the meantime + s.txnMarkSet = markSet + + // and do it again while holding the lock to mark references that might have been created + // in the meantime and avoid races of the type Has->txnRef->enterCS->Get fails because + // it's not in the markset if err := s.protectTxnRefs(markSet); err != nil { return xerrors.Errorf("error protecting transactional references: %w", err) }