Prechádzať zdrojové kódy

Add IMGPROXY_GRACEFUL_STOP_TIMEOUT config

DarthSim 3 týždňov pred
rodič
commit
7da78ef191
3 zmenil súbory, kde vykonal 12 pridanie a 2 odobranie
  1. 3 1
      CHANGELOG.md
  2. 5 0
      config/config.go
  3. 4 1
      server.go

+ 3 - 1
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.
 

+ 5 - 0
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")

+ 4 - 1
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)