From a9b863ea51bad2af8b2b9d129e36c1838b9a02db Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 8 Jul 2019 15:33:48 +0200 Subject: [PATCH] eth: fix crash in ethclient tests --- eth/backend.go | 2 +- eth/enr_entry.go | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/eth/backend.go b/eth/backend.go index 052bfad0f9..dc4ff8ade8 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -522,7 +522,7 @@ func (s *Ethereum) Protocols() []p2p.Protocol { // Start implements node.Service, starting all internal goroutines needed by the // Ethereum protocol implementation. func (s *Ethereum) Start(srvr *p2p.Server) error { - go s.enrUpdateLoop(srvr.LocalNode()) + s.startEthEntryUpdate(srvr.LocalNode()) // Start the bloom bits servicing goroutines s.startBloomHandlers(params.BloomBitsBlocks) diff --git a/eth/enr_entry.go b/eth/enr_entry.go index 3798440da4..d9e7b95784 100644 --- a/eth/enr_entry.go +++ b/eth/enr_entry.go @@ -37,21 +37,23 @@ func (e ethEntry) ENRKey() string { return "eth" } -func (eth *Ethereum) enrUpdateLoop(ln *enode.LocalNode) { +func (eth *Ethereum) startEthEntryUpdate(ln *enode.LocalNode) { var newHead = make(chan core.ChainHeadEvent, 10) sub := eth.blockchain.SubscribeChainHeadEvent(newHead) - defer sub.Unsubscribe() - for { - select { - case <-newHead: - ln.Set(eth.currentEthEntry()) - case <-sub.Err(): - // Would be nice to sync with eth.Stop, but there is no - // good way to do that. - return + go func() { + defer sub.Unsubscribe() + for { + select { + case <-newHead: + ln.Set(eth.currentEthEntry()) + case <-sub.Err(): + // Would be nice to sync with eth.Stop, but there is no + // good way to do that. + return + } } - } + }() } func (eth *Ethereum) currentEthEntry() *ethEntry {