eth/handler: fix blocking on stop

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2026-01-15 13:56:17 +01:00
parent 479a57d3d9
commit ac65a7cd87
No known key found for this signature in database
GPG key ID: 0FE274EE8C95166E

View file

@ -740,7 +740,17 @@ func (h *handler) txOnChainCacheLoop() {
//Subscribe to chain events to know when transactions are added to chain
headEventCh := make(chan core.ChainEvent, 10)
sub := h.chain.SubscribeChainEvent(headEventCh)
defer sub.Unsubscribe()
defer func() {
sub.Unsubscribe()
// drain channel
for {
select {
case <-headEventCh:
default:
return
}
}
}()
var oldHead *types.Header
for {
@ -762,6 +772,8 @@ func (h *handler) txOnChainCacheLoop() {
// exit when the subscription ends
case <-sub.Err():
return
case <-h.quitSync:
return
}
}
}