From 2d97c7637c3a65611f197eb4fe362e3410d2d540 Mon Sep 17 00:00:00 2001 From: robertotting Date: Mon, 29 Apr 2024 12:32:30 -0500 Subject: [PATCH] feat(cmd/serve): add in default-shutdown-timeout flag to increase shutdown timeout on http server shutdown --- cmd/serve.go | 1 + cmd/server/server.go | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/cmd/serve.go b/cmd/serve.go index fb93bcab89..2656fba177 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -32,4 +32,5 @@ func init() { serveCmd.PersistentFlags().Bool("disable-telemetry", false, "Disable anonymized telemetry reports - for more information please visit https://www.ory.sh/docs/ecosystem/sqa") serveCmd.PersistentFlags().Bool("sqa-opt-out", false, "Disable anonymized telemetry reports - for more information please visit https://www.ory.sh/docs/ecosystem/sqa") + serveCmd.PersistentFlags().Int("default-shutdown-timeout", 5, "Set the default shutdown timeout in seconds for server shutdown when trapping SIGTERM and SIGINT") } diff --git a/cmd/server/server.go b/cmd/server/server.go index 06b294e2dc..de21b2e720 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -251,6 +251,13 @@ func RunServe(version, build, date string) func(cmd *cobra.Command, args []strin adminmw.Use(telemetry) publicmw.Use(telemetry) + // Override the `graceful.DefaultShutdownTimeout` value + graceful.DefaultShutdownTimeout = 5 * time.Second + defaultShutdownTimeout, _ := cmd.Flags().GetInt("default-shutdown-timeout") + if defaultShutdownTimeout > 0 { + graceful.DefaultShutdownTimeout = time.Duration(defaultShutdownTimeout) * time.Second + } + prometheusRepo := metrics.NewConfigurablePrometheusRepository(d, logger) var wg sync.WaitGroup tasks := []func(){