mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-20 07:19:17 +01:00
lib/httpserver: add -http.maxGracefulShutdownDuration
command-line flag for tuning the maximum duration required for graceful shutdown of http server
This commit is contained in:
parent
b22da547a2
commit
149f365f74
@ -33,6 +33,8 @@ var (
|
|||||||
pprofAuthKey = flag.String("pprofAuthKey", "", "Auth key for /debug/pprof. It overrides httpAuth settings")
|
pprofAuthKey = flag.String("pprofAuthKey", "", "Auth key for /debug/pprof. It overrides httpAuth settings")
|
||||||
|
|
||||||
disableResponseCompression = flag.Bool("http.disableResponseCompression", false, "Disable compression of HTTP responses for saving CPU resources. By default compression is enabled to save network bandwidth")
|
disableResponseCompression = flag.Bool("http.disableResponseCompression", false, "Disable compression of HTTP responses for saving CPU resources. By default compression is enabled to save network bandwidth")
|
||||||
|
maxGracefulShutdownDuration = flag.Duration("http.maxGracefulShutdownDuration", 7*time.Second, "The maximum duration for graceful shutdown of HTTP server. "+
|
||||||
|
"Highly loaded server may require increased value for graceful shutdown")
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -130,10 +132,10 @@ func Stop(addr string) error {
|
|||||||
if s == nil {
|
if s == nil {
|
||||||
logger.Panicf("BUG: there is no http server at %q", addr)
|
logger.Panicf("BUG: there is no http server at %q", addr)
|
||||||
}
|
}
|
||||||
ctx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Second)
|
ctx, cancelFunc := context.WithTimeout(context.Background(), *maxGracefulShutdownDuration)
|
||||||
defer cancelFunc()
|
defer cancelFunc()
|
||||||
if err := s.Shutdown(ctx); err != nil {
|
if err := s.Shutdown(ctx); err != nil {
|
||||||
return fmt.Errorf("cannot gracefully shutdown http server at %q: %s", addr, err)
|
return fmt.Errorf("cannot gracefully shutdown http server at %q in %.3fs: %s", addr, maxGracefulShutdownDuration.Seconds(), err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user