mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
eth/handler: fix blocking on stop
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
479a57d3d9
commit
ac65a7cd87
1 changed files with 13 additions and 1 deletions
|
|
@ -740,7 +740,17 @@ func (h *handler) txOnChainCacheLoop() {
|
||||||
//Subscribe to chain events to know when transactions are added to chain
|
//Subscribe to chain events to know when transactions are added to chain
|
||||||
headEventCh := make(chan core.ChainEvent, 10)
|
headEventCh := make(chan core.ChainEvent, 10)
|
||||||
sub := h.chain.SubscribeChainEvent(headEventCh)
|
sub := h.chain.SubscribeChainEvent(headEventCh)
|
||||||
defer sub.Unsubscribe()
|
defer func() {
|
||||||
|
sub.Unsubscribe()
|
||||||
|
// drain channel
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-headEventCh:
|
||||||
|
default:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
var oldHead *types.Header
|
var oldHead *types.Header
|
||||||
for {
|
for {
|
||||||
|
|
@ -762,6 +772,8 @@ func (h *handler) txOnChainCacheLoop() {
|
||||||
// exit when the subscription ends
|
// exit when the subscription ends
|
||||||
case <-sub.Err():
|
case <-sub.Err():
|
||||||
return
|
return
|
||||||
|
case <-h.quitSync:
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue