Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: crash on nil access when TxPool shutdown #1356

Merged
merged 2 commits into from
Mar 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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