fix race in protectView

This commit is contained in:
vyzo 2022-01-31 12:40:26 +02:00
parent 1900c907fd
commit ee63be26a1
2 changed files with 2 additions and 3 deletions

View File

@ -494,7 +494,7 @@ func (s *SplitStore) View(ctx context.Context, cid cid.Cid, cb func([]byte) erro
}
// critical section
s.txnLk.RLock()
s.txnLk.RLock() // the lock is released in protectView if we are not in critical section
if s.txnMarkSet != nil {
has, err := s.txnMarkSet.Has(cid)
s.txnLk.RUnlock()
@ -509,7 +509,6 @@ func (s *SplitStore) View(ctx context.Context, cid cid.Cid, cb func([]byte) erro
return s.cold.View(ctx, cid, cb)
}
s.txnLk.RUnlock()
// views are (optimistically) protected two-fold:
// - if there is an active transaction, then the reference is protected.

View File

@ -156,7 +156,7 @@ func (s *SplitStore) protectTipSets(apply []*types.TipSet) {
// transactionally protect a view
func (s *SplitStore) protectView(c cid.Cid) {
s.txnLk.RLock()
// the txnLk is held for read
defer s.txnLk.RUnlock()
if s.txnActive {