blockfetcher: change shutdown logic

Move the `isActive` check earlier to enable faster shutdown and prevent
the service from hanging.

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
This commit is contained in:
Ekaterina Pavlova 2024-11-28 14:44:14 +03:00
parent 8216f538c3
commit df05cd2858

View file

@ -492,6 +492,7 @@ func (bfs *Service) exiter() {
zap.Bool("force", force),
)
bfs.isActive.CompareAndSwap(true, false)
// Cansel all pending OIDs/blocks downloads in case if shutdown requested by user
// or caused by downloading error.
if force {
@ -516,7 +517,6 @@ func (bfs *Service) exiter() {
// the server know about it.
_ = bfs.pool.Close()
_ = bfs.log.Sync()
bfs.isActive.CompareAndSwap(true, false)
bfs.shutdownCallback()
// Notify Shutdown routine in case if it's user-triggered shutdown.