Skip to content

Commit

Permalink
fix: crash on nil access when TxPool shutdown (#1353) (#1356)
Browse files Browse the repository at this point in the history
  • Loading branch information
brilliant-lx authored Mar 15, 2023
1 parent 7b6cebe commit fc4303c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,12 @@ LOOP:
// subscribe before fillTransactions
txsCh := make(chan core.NewTxsEvent, txChanSize)
sub := w.eth.TxPool().SubscribeNewTxsEvent(txsCh)
defer sub.Unsubscribe()
// if TxPool has been stopped, `sub` would be nil, it could happen on shutdown.
if sub == nil {
log.Info("commitWork SubscribeNewTxsEvent return nil")
} else {
defer sub.Unsubscribe()
}

// Fill pending transactions from the txpool
fillStart := time.Now()
Expand Down Expand Up @@ -1196,7 +1201,9 @@ LOOP:
}
// if sub's channel if full, it will block other NewTxsEvent subscribers,
// so unsubscribe ASAP and Unsubscribe() is re-enterable, safe to call several time.
sub.Unsubscribe()
if sub != nil {
sub.Unsubscribe()
}
}
// get the most profitable work
bestWork := workList[0]
Expand Down

0 comments on commit fc4303c

Please sign in to comment.