From 156ba420c320dfda8cee5d5281c0810490c4be9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sat, 17 Dec 2022 13:12:33 +0100 Subject: [PATCH] fix: splitstore: Don't deadlock in mpool protector --- chain/messagepool/messagepool.go | 8 ++++++-- node/modules/chain.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/chain/messagepool/messagepool.go b/chain/messagepool/messagepool.go index 0724f145f..94ae62673 100644 --- a/chain/messagepool/messagepool.go +++ b/chain/messagepool/messagepool.go @@ -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 { diff --git a/node/modules/chain.go b/node/modules/chain.go index 22a1d618a..49418d883 100644 --- a/node/modules/chain.go +++ b/node/modules/chain.go @@ -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 }