From 7da78ef191be98595946455f6c0ae385bdc649f5 Mon Sep 17 00:00:00 2001 From: DarthSim Date: Mon, 8 Sep 2025 20:32:23 +0300 Subject: [PATCH] Add IMGPROXY_GRACEFUL_STOP_TIMEOUT config --- CHANGELOG.md | 4 +++- config/config.go | 5 +++++ server.go | 5 ++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdf9e9dd..c216e324 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,11 @@ ## [Unreleased] ### Added -- (pro) Add [color_profile](https://docs.imgproxy.net/latest/usage/processing#color-profile) processing option and [IMGPROXY_COLOR_PROFILES_DIR](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_COLOR_PROFILES_DIR) config +- Add [IMGPROXY_GRACEFUL_STOP_TIMEOUT](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_GRACEFUL_STOP_TIMEOUT) config. +- (pro) Add [color_profile](https://docs.imgproxy.net/latest/usage/processing#color-profile) processing option and [IMGPROXY_COLOR_PROFILES_DIR](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_COLOR_PROFILES_DIR) config. ### Changed +- Update the default graceful stop timeout to twice the [IMGPROXY_TIMEOUT](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_TIMEOUT) config value. - (pro) Improve video decoding performance. - (pro) Respond with `422 Unprocessable Entity` on error during video decoding. diff --git a/config/config.go b/config/config.go index b572b695..1e97c16b 100644 --- a/config/config.go +++ b/config/config.go @@ -23,6 +23,7 @@ var ( Network string Bind string Timeout int + GracefulStopTimeout int ReadRequestTimeout int WriteResponseTimeout int KeepAliveTimeout int @@ -231,6 +232,7 @@ func Reset() { Network = "tcp" Bind = ":8080" Timeout = 10 + GracefulStopTimeout = 20 ReadRequestTimeout = 10 WriteResponseTimeout = 10 KeepAliveTimeout = 10 @@ -438,6 +440,9 @@ func Configure() error { } configurators.Int(&Timeout, "IMGPROXY_TIMEOUT") + GracefulStopTimeout = Timeout * 2 + configurators.Int(&GracefulStopTimeout, "IMGPROXY_GRACEFUL_STOP_TIMEOUT") + if _, ok := os.LookupEnv("IMGPROXY_READ_TIMEOUT"); ok { log.Warning("IMGPROXY_READ_TIMEOUT is deprecated, use IMGPROXY_READ_REQUEST_TIMEOUT instead") configurators.Int(&ReadRequestTimeout, "IMGPROXY_READ_TIMEOUT") diff --git a/server.go b/server.go index f437684b..f7741336 100644 --- a/server.go +++ b/server.go @@ -80,7 +80,10 @@ func startServer(cancel context.CancelFunc) (*http.Server, error) { func shutdownServer(s *http.Server) { log.Info("Shutting down the server...") - ctx, close := context.WithTimeout(context.Background(), 5*time.Second) + ctx, close := context.WithTimeout( + context.Background(), + time.Duration(config.GracefulStopTimeout)*time.Second, + ) defer close() s.Shutdown(ctx)