Skip to content

Commit

Permalink
Properly close deps channel (#1197)
Browse files Browse the repository at this point in the history
In case where commitTransactions is interrupted, it will exit without properly closing chDeps, leaving the dependency calculation goroutine hanging. This commit fixes this issue.
  • Loading branch information
cffls authored Mar 22, 2024
1 parent 5461f9b commit 8be2283
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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) {
Expand Down Expand Up @@ -1109,7 +1115,9 @@ mainloop:

// nolint:nestif
if EnableMVHashMap && w.IsRunning() {
close(chDeps)
once.Do(func() {
close(chDeps)
})
depsWg.Wait()

var blockExtraData types.BlockExtraData
Expand Down

0 comments on commit 8be2283

Please sign in to comment.