diff --git a/cmd/vspd/vspd.go b/cmd/vspd/vspd.go index f362175..5e79927 100644 --- a/cmd/vspd/vspd.go +++ b/cmd/vspd/vspd.go @@ -116,7 +116,7 @@ func (v *vspd) run() int { // Create a context that is cancelled when a shutdown request is received // through an interrupt signal. - shutdownCtx := shutdownListener(v.log) + ctx := shutdownListener(v.log) // Run database integrity checks to ensure all data in database is present // and up-to-date. @@ -151,7 +151,7 @@ func (v *vspd) run() int { MaxVoteChangeRecords: maxVoteChangeRecords, VspdVersion: version.String(), } - err = webapi.Start(shutdownCtx, requestShutdown, &shutdownWg, v.cfg.Listen, v.db, v.cfg.logger("API"), + err = webapi.Start(ctx, requestShutdown, &shutdownWg, v.cfg.Listen, v.db, v.cfg.logger("API"), v.dcrd, v.wallets, apiCfg) if err != nil { v.log.Errorf("Failed to initialize webapi: %v", err) @@ -197,7 +197,7 @@ func (v *vspd) run() int { v.blockConnected() // Handle shutdown request. - case <-shutdownCtx.Done(): + case <-ctx.Done(): shutdownWg.Done() return } diff --git a/webapi/webapi.go b/webapi/webapi.go index e3f30d9..e460abb 100644 --- a/webapi/webapi.go +++ b/webapi/webapi.go @@ -75,7 +75,7 @@ type Server struct { signPubKey ed25519.PublicKey } -func Start(shutdownCtx context.Context, requestShutdown func(), shutdownWg *sync.WaitGroup, +func Start(ctx context.Context, requestShutdown func(), shutdownWg *sync.WaitGroup, listen string, vdb *database.VspDatabase, log slog.Logger, dcrd rpc.DcrdConnect, wallets rpc.WalletConnect, config Config) error { @@ -123,7 +123,7 @@ func Start(shutdownCtx context.Context, requestShutdown func(), shutdownWg *sync // Create TCP listener. var listenConfig net.ListenConfig - listener, err := listenConfig.Listen(shutdownCtx, "tcp", listen) + listener, err := listenConfig.Listen(ctx, "tcp", listen) if err != nil { return err } @@ -139,7 +139,7 @@ func Start(shutdownCtx context.Context, requestShutdown func(), shutdownWg *sync shutdownWg.Add(1) go func() { // Wait until shutdown is signaled before shutting down. - <-shutdownCtx.Done() + <-ctx.Done() log.Debug("Stopping webserver...") // Give the webserver 5 seconds to finish what it is doing. @@ -176,7 +176,7 @@ func Start(shutdownCtx context.Context, requestShutdown func(), shutdownWg *sync go func() { for { select { - case <-shutdownCtx.Done(): + case <-ctx.Done(): shutdownWg.Done() return case <-time.After(refresh):