Skip to content

Commit 13ee157

Browse files
committed
Don't allocate the mempool sync thread in the top level registry
1 parent 83a00de commit 13ee157

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
For top level release notes, leave all the headers commented out.
6+
-->
7+
8+
### Patch
9+
10+
- The Mempool sync thread was allocated in the top level registry in order to
11+
ensure it would be cancelled before the mempool registry was shutting
12+
down. This was solved in `resource-registry-0.2.0.0`.
13+
14+
<!--
15+
### Non-Breaking
16+
17+
- A bullet item for the Non-Breaking category.
18+
19+
-->
20+
<!--
21+
### Breaking
22+
23+
- A bullet item for the Breaking category.
24+
25+
-->

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Mempool/Init.hs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ openMempool ::
4141
m (Mempool m blk)
4242
openMempool topLevelRegistry ledger cfg capacityOverride tracer = do
4343
env <- initMempoolEnv ledger cfg capacityOverride tracer topLevelRegistry
44-
forkSyncStateOnTipPointChange topLevelRegistry env
44+
forkSyncStateOnTipPointChange env
4545
return $ mkMempool env
4646

4747
-- | Spawn a thread which syncs the 'Mempool' state whenever the 'LedgerState'
@@ -53,11 +53,10 @@ forkSyncStateOnTipPointChange ::
5353
, HasTxId (GenTx blk)
5454
, ValidateEnvelope blk
5555
) =>
56-
ResourceRegistry m ->
5756
MempoolEnv m blk ->
5857
m ()
59-
forkSyncStateOnTipPointChange topLevelRegistry menv = do
60-
w <-
58+
forkSyncStateOnTipPointChange menv =
59+
void $
6160
forkLinkedWatcher
6261
(mpEnvRegistry menv)
6362
"Mempool.syncStateOnTipPointChange"
@@ -67,12 +66,6 @@ forkSyncStateOnTipPointChange topLevelRegistry menv = do
6766
, wNotify = action
6867
, wReader = getCurrentTip
6968
}
70-
71-
-- With this allocation on the top level registry, we make sure that we first
72-
-- stop the watcher thread before closing the mempool registry, as otherwise
73-
-- we would run into a race condition (the thread might try to re-sync and
74-
-- allocate a forker on the mempool registry which would be closing down).
75-
void $ allocate topLevelRegistry (\_ -> pure w) cancelThread
7669
where
7770
action :: MempoolLedgerDBView m blk -> m ()
7871
action _a =

0 commit comments

Comments
 (0)