From 109319d220466f02932171d153c6e458866d76cf Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 6 Dec 2024 11:38:42 +0300 Subject: [PATCH] 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) }