vspd: Create shutdown context earlier.

Create the shutdown context earlier so process begins handling shutdown
signals earlier. Specifically, the context should be created before
creating any resources which need a graceful shutdown such as the
database. This is important because without explicit signal handling the
process will terminate immediately upon receiving a signal without
running deferred tasks.
This commit is contained in:
jholdstock 2023-09-20 09:38:50 +01:00 committed by Jamie Holdstock
parent 81784accb6
commit fb1f250a74

View File

@ -45,6 +45,10 @@ func run() int {
log := cfg.logger("VSP") log := cfg.logger("VSP")
// Create a context that is canceled when a shutdown request is received
// through an interrupt signal such as SIGINT (Ctrl+C).
ctx := signal.ShutdownListener(log)
defer log.Criticalf("Shutdown complete") defer log.Criticalf("Shutdown complete")
log.Criticalf("Version %s (Go version %s %s/%s)", version.String(), log.Criticalf("Version %s (Go version %s %s/%s)", version.String(),
runtime.Version(), runtime.GOOS, runtime.GOARCH) runtime.Version(), runtime.GOOS, runtime.GOARCH)
@ -107,10 +111,6 @@ func run() int {
// WaitGroup for services to signal when they have shutdown cleanly. // WaitGroup for services to signal when they have shutdown cleanly.
var shutdownWg sync.WaitGroup var shutdownWg sync.WaitGroup
// Create a context that is canceled when a shutdown request is received
// through an interrupt signal such as SIGINT (Ctrl+C).
ctx := signal.ShutdownListener(log)
// Start the webapi server. // Start the webapi server.
shutdownWg.Add(1) shutdownWg.Add(1)
go func() { go func() {