Skip to content

Commit

Permalink
Merge pull request #9903 from filecoin-project/fix/splitstore-compact…
Browse files Browse the repository at this point in the history
…-dlock

fix: splitstore: Don't deadlock in mpool protector
  • Loading branch information
arajasek authored Dec 19, 2022
2 parents 1dee884 + 156ba42 commit 6388eca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions chain/messagepool/messagepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,12 @@ func New(ctx context.Context, api Provider, ds dtypes.MetadataDS, us stmgr.Upgra
return mp, nil
}

func (mp *MessagePool) ForEachPendingMessage(f func(cid.Cid) error) error {
mp.lk.Lock()
func (mp *MessagePool) TryForEachPendingMessage(f func(cid.Cid) error) error {
// avoid deadlocks in splitstore compaction when something else needs to access the blockstore
// while holding the mpool lock
if !mp.lk.TryLock() {
return xerrors.Errorf("mpool TryForEachPendingMessage: could not acquire lock")
}
defer mp.lk.Unlock()

for _, mset := range mp.pending {
Expand Down
2 changes: 1 addition & 1 deletion node/modules/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func MessagePool(lc fx.Lifecycle, mctx helpers.MetricsCtx, us stmgr.UpgradeSched
return mp.Close()
},
})
protector.AddProtector(mp.ForEachPendingMessage)
protector.AddProtector(mp.TryForEachPendingMessage)
return mp, nil
}

Expand Down

0 comments on commit 6388eca

Please sign in to comment.