From a63e2f124716c1f86e0a841d0abad017af21fa05 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Thu, 25 Jun 2026 19:10:54 +0800 Subject: [PATCH] eth/downloader: fix test panic (#35215) This PR addresses the panic in tests. As the eventLoop is spun up when the downloader was closed, the sub will be nil and make the panic happens. ``` goroutine 421 [running]: github.com/ethereum/go-ethereum/eth/downloader.(*DownloaderAPI).eventLoop(0xcb0e4d0) /opt/actions-runner/_work/go-ethereum/go-ethereum/eth/downloader/api.go:91 +0x127 created by github.com/ethereum/go-ethereum/eth/downloader.NewDownloaderAPI in goroutine 352 /opt/actions-runner/_work/go-ethereum/go-ethereum/eth/downloader/api.go:50 +0xf2 ``` --- eth/downloader/api.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/eth/downloader/api.go b/eth/downloader/api.go index 6033e44474..4f950cd671 100644 --- a/eth/downloader/api.go +++ b/eth/downloader/api.go @@ -62,9 +62,12 @@ func NewDownloaderAPI(d *Downloader, chain *core.BlockChain) *DownloaderAPI { // If the node is already synced up, then only a single event subscribers will // receive is {false}. func (api *DownloaderAPI) eventLoop() { + events := make(chan SyncEvent, 16) + sub := api.d.SubscribeSyncEvents(events) + if sub == nil { + return + } var ( - events = make(chan SyncEvent, 16) - sub = api.d.SubscribeSyncEvents(events) syncSubscriptions = make(map[chan interface{}]struct{}) checkInterval = time.Second * 60 checkTimer = time.NewTimer(checkInterval)