Skip to content

Commit

Permalink
txpool: fix a potential crash issue in shutdown; (#1951)
Browse files Browse the repository at this point in the history
  • Loading branch information
galaio authored and brilliant-lx committed Oct 31, 2023
1 parent 4493ab8 commit 0b69113
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,11 @@ func (p *TxPool) Pending(enforceTips bool) map[common.Address][]*LazyTransaction
// SubscribeNewTxsEvent registers a subscription of NewTxsEvent and starts sending
// events to the given channel.
func (p *TxPool) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription {
subs := make([]event.Subscription, len(p.subpools))
for i, subpool := range p.subpools {
subs := make([]event.Subscription, 0, len(p.subpools))
for _, subpool := range p.subpools {
sub := subpool.SubscribeTransactions(ch)
if sub != nil { // sub will be nil when subpool have been shut down
subs[i] = sub
subs = append(subs, sub)
}
}
return p.subs.Track(event.JoinSubscriptions(subs...))
Expand All @@ -332,11 +332,11 @@ func (p *TxPool) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscrip
// SubscribeNewTxsEvent registers a subscription of NewTxsEvent and starts sending
// events to the given channel.
func (p *TxPool) SubscribeReannoTxsEvent(ch chan<- core.ReannoTxsEvent) event.Subscription {
subs := make([]event.Subscription, len(p.subpools))
for i, subpool := range p.subpools {
subs := make([]event.Subscription, 0, len(p.subpools))
for _, subpool := range p.subpools {
sub := subpool.SubscribeReannoTxsEvent(ch)
if sub != nil { // sub will be nil when subpool have been shut down
subs[i] = sub
subs = append(subs, sub)
}
}
return p.subs.Track(event.JoinSubscriptions(subs...))
Expand Down

0 comments on commit 0b69113

Please sign in to comment.