mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 01:43:47 +00:00
eth/gasprice: ensure goroutine that that purges cache upon reorg doesn't hang after dependent subscription is closed
This commit is contained in:
parent
864e717b56
commit
0510fc8662
1 changed files with 10 additions and 5 deletions
|
|
@ -120,14 +120,19 @@ func NewOracle(backend OracleBackend, params Config, startPrice *big.Int) *Oracl
|
||||||
|
|
||||||
cache := lru.NewCache[cacheKey, processedFees](2048)
|
cache := lru.NewCache[cacheKey, processedFees](2048)
|
||||||
headEvent := make(chan core.ChainHeadEvent, 1)
|
headEvent := make(chan core.ChainHeadEvent, 1)
|
||||||
backend.SubscribeChainHeadEvent(headEvent)
|
sub := backend.SubscribeChainHeadEvent(headEvent)
|
||||||
go func() {
|
go func() {
|
||||||
var lastHead common.Hash
|
var lastHead common.Hash
|
||||||
for ev := range headEvent {
|
for {
|
||||||
|
select {
|
||||||
|
case ev := <-headEvent:
|
||||||
if ev.Header.ParentHash != lastHead {
|
if ev.Header.ParentHash != lastHead {
|
||||||
cache.Purge()
|
cache.Purge()
|
||||||
}
|
}
|
||||||
lastHead = ev.Header.Hash()
|
lastHead = ev.Header.Hash()
|
||||||
|
case <-sub.Err():
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue