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.
This commit is contained in:
Jerry 2024-03-21 23:31:10 -07:00 committed by GitHub
parent 5461f9bdc4
commit 8be2283e7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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