fix: add context parameter to route registration functions for improved lifecycle management

This commit is contained in:
GitHub Actions
2026-04-13 14:10:44 +00:00
parent 0391f2b3e3
commit 29c56ab283
8 changed files with 75 additions and 70 deletions

View File

@@ -255,7 +255,11 @@ func main() {
cerb := cerberus.New(cfg.Security, db)
// Pass config to routes for auth service and certificate service
if err := routes.RegisterWithDeps(router, db, cfg, caddyManager, cerb); err != nil {
// Lifecycle context cancelled on shutdown to stop background goroutines
appCtx, appCancel := context.WithCancel(context.Background())
defer appCancel()
if err := routes.RegisterWithDeps(appCtx, router, db, cfg, caddyManager, cerb); err != nil {
log.Fatalf("register routes: %v", err)
}
@@ -291,6 +295,9 @@ func main() {
sig := <-quit
logger.Log().Infof("Received signal %v, initiating graceful shutdown...", sig)
// Cancel the app-wide context to stop background goroutines (e.g. cert expiry checker)
appCancel()
// Graceful shutdown with timeout
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()