From 8be2283e7a25a360d33c277a7deddf56adfd8aea Mon Sep 17 00:00:00 2001 From: Jerry Date: Thu, 21 Mar 2024 23:31:10 -0700 Subject: [PATCH] Properly close deps channel (#1197) In case where commitTransactions is interrupted, it will exit without properly closing chDeps, leaving the dependency calculation goroutine hanging. This commit fixes this issue. --- miner/worker.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/miner/worker.go b/miner/worker.go index ae96bc721e..5b3c754f49 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -921,6 +921,7 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn chDeps := make(chan blockstm.TxDep) var depsWg sync.WaitGroup + var once sync.Once EnableMVHashMap := w.chainConfig.IsCancun(env.header.Number) @@ -930,6 +931,11 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn chDeps = make(chan blockstm.TxDep) + // Make sure we safely close the channel in case of interrupt + defer once.Do(func() { + close(chDeps) + }) + depsWg.Add(1) go func(chDeps chan blockstm.TxDep) { @@ -1109,7 +1115,9 @@ mainloop: // nolint:nestif if EnableMVHashMap && w.IsRunning() { - close(chDeps) + once.Do(func() { + close(chDeps) + }) depsWg.Wait() var blockExtraData types.BlockExtraData