From c812150d831c1f23db99b3ca21a691b5d1744e2c Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 6 Dec 2024 11:34:07 +0300 Subject: [PATCH 1/2] network: avoid looping forever blockFetcherFin is closed by the block fetcher, so it will forever return something in this loop making it an infinite loop, creating useless load and affecting normal node operation. Signed-off-by: Roman Khimov --- pkg/network/server.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/network/server.go b/pkg/network/server.go index e4d25485d..8d9f6c8a7 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -575,6 +575,7 @@ func (s *Server) run() { s.tryInitStateSync() s.tryStartServices() } + s.blockFetcherFin = nil } } } From 109319d220466f02932171d153c6e458866d76cf Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 6 Dec 2024 11:38:42 +0300 Subject: [PATCH 2/2] network: avoid accidental double-close of blockFetcherFin channel It's not supposed to happen, but if blockfetcher goes wild and calls this twice it can ruin the system, so better safe than sorry. Signed-off-by: Roman Khimov --- pkg/network/server.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/network/server.go b/pkg/network/server.go index 8d9f6c8a7..ab52cf1bd 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -226,9 +226,8 @@ func newServerFromConstructors(config ServerConfig, chain Ledger, stSync StateSy s.bSyncQueue = bqueue.New(s.stateSync, log, nil, bqueue.DefaultCacheSize, updateBlockQueueLenMetric, bqueue.NonBlocking) s.bFetcherQueue = bqueue.New(chain, log, nil, s.NeoFSBlockFetcherCfg.BQueueSize, updateBlockQueueLenMetric, bqueue.Blocking) var err error - s.blockFetcher, err = blockfetcher.New(chain, s.NeoFSBlockFetcherCfg, log, s.bFetcherQueue.PutBlock, func() { - close(s.blockFetcherFin) - }) + s.blockFetcher, err = blockfetcher.New(chain, s.NeoFSBlockFetcherCfg, log, s.bFetcherQueue.PutBlock, + sync.OnceFunc(func() { close(s.blockFetcherFin) })) if err != nil { return nil, fmt.Errorf("failed to create NeoFS BlockFetcher: %w", err) }