From b0f79e56f5ecaa3f557c08f22415bc100adac131 Mon Sep 17 00:00:00 2001 From: jholdstock Date: Thu, 7 Sep 2023 15:44:02 +0100 Subject: [PATCH] vspd: Exit if shutdown requested during startup. vspd runs some tasks on startup - database consistency checks, catching up with missed blocks, etc. If a shutdown is requested while these tasks are running, vspd should stop immediately rather than continuing to start the web API server and other background tasks. --- cmd/vspd/vspd.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmd/vspd/vspd.go b/cmd/vspd/vspd.go index 5e79927..78b842f 100644 --- a/cmd/vspd/vspd.go +++ b/cmd/vspd/vspd.go @@ -126,14 +126,29 @@ func (v *vspd) run() int { v.log.Errorf("Database integrity check failed: %v", err) } + // Stop if shutdown requested. + if ctx.Err() != nil { + return 0 + } + // Run the block connected handler now to catch up with any blocks mined // while vspd was shut down. v.blockConnected() + // Stop if shutdown requested. + if ctx.Err() != nil { + return 0 + } + // Run voting wallet consistency check now to ensure all wallets are up to // date. v.checkWalletConsistency() + // Stop if shutdown requested. + if ctx.Err() != nil { + return 0 + } + // WaitGroup for services to signal when they have shutdown cleanly. var shutdownWg sync.WaitGroup