diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f390ebe..04c207f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ ### Changed - Automatically add `http://` scheme to the `IMGPROXY_S3_ENDPOINT` value if it has no scheme. - Trim redundant slashes in the S3 object key. +- Rename `IMGPROXY_WRITE_TIMEOUT` to `IMGPROXY_TIMEOUT`. The old name is deprecated but still supported. +- Rename `IMGPROXY_READ_TIMEOUT` to `IMGPROXY_READ_REQUEST_TIMEOUT`. The old name is deprecated but still supported. - (pro) Allow specifying [gradient](https://docs.imgproxy.net/latest/usage/processing#gradient) direction as an angle in degrees. ### Fix @@ -18,6 +20,10 @@ - (pro) Fix style injection to SVG. - (pro) Fix video tiles generation when the video's SAR is not `1`. +### Deprecated +- `IMGPROXY_WRITE_TIMEOUT` config is deprecated. Use `IMGPROXY_TIMEOUT` instead. +- `IMGPROXY_READ_TIMEOUT` config is deprecated. Use `IMGPROXY_READ_REQUEST_TIMEOUT` instead. + ## [3.24.1] - 2024-04-30 ### Fix - Fix the default `IMGPROXY_WORKERS` value when cgroup limits are applied. diff --git a/config/config.go b/config/config.go index 78090d6f..4d314cd9 100644 --- a/config/config.go +++ b/config/config.go @@ -21,8 +21,8 @@ type URLReplacement = configurators.URLReplacement var ( Network string Bind string - ReadTimeout int - WriteTimeout int + Timeout int + ReadRequestTimeout int WriteResponseTimeout int KeepAliveTimeout int ClientKeepAliveTimeout int @@ -217,8 +217,8 @@ func init() { func Reset() { Network = "tcp" Bind = ":8080" - ReadTimeout = 10 - WriteTimeout = 10 + Timeout = 10 + ReadRequestTimeout = 10 WriteResponseTimeout = 10 KeepAliveTimeout = 10 ClientKeepAliveTimeout = 90 @@ -403,11 +403,24 @@ func Configure() error { configurators.String(&Network, "IMGPROXY_NETWORK") configurators.String(&Bind, "IMGPROXY_BIND") - configurators.Int(&ReadTimeout, "IMGPROXY_READ_TIMEOUT") - configurators.Int(&WriteTimeout, "IMGPROXY_WRITE_TIMEOUT") + + if _, ok := os.LookupEnv("IMGPROXY_WRITE_TIMEOUT"); ok { + log.Warning("IMGPROXY_WRITE_TIMEOUT is deprecated, use IMGPROXY_TIMEOUT instead") + configurators.Int(&Timeout, "IMGPROXY_WRITE_TIMEOUT") + } + configurators.Int(&Timeout, "IMGPROXY_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") + } + configurators.Int(&ReadRequestTimeout, "IMGPROXY_READ_REQUEST_TIMEOUT") + configurators.Int(&WriteResponseTimeout, "IMGPROXY_WRITE_RESPONSE_TIMEOUT") + configurators.Int(&KeepAliveTimeout, "IMGPROXY_KEEP_ALIVE_TIMEOUT") configurators.Int(&ClientKeepAliveTimeout, "IMGPROXY_CLIENT_KEEP_ALIVE_TIMEOUT") + configurators.Int(&DownloadTimeout, "IMGPROXY_DOWNLOAD_TIMEOUT") if lambdaFn := os.Getenv("AWS_LAMBDA_FUNCTION_NAME"); len(lambdaFn) > 0 { @@ -627,12 +640,14 @@ func Configure() error { return errors.New("Bind address is not defined") } - if ReadTimeout <= 0 { - return fmt.Errorf("Read timeout should be greater than 0, now - %d\n", ReadTimeout) + if Timeout <= 0 { + return fmt.Errorf("Timeout should be greater than 0, now - %d\n", Timeout) } - - if WriteTimeout <= 0 { - return fmt.Errorf("Write timeout should be greater than 0, now - %d\n", WriteTimeout) + if ReadRequestTimeout <= 0 { + return fmt.Errorf("Read request timeout should be greater than 0, now - %d\n", ReadRequestTimeout) + } + if WriteResponseTimeout <= 0 { + return fmt.Errorf("Write response timeout should be greater than 0, now - %d\n", WriteResponseTimeout) } if KeepAliveTimeout < 0 { return fmt.Errorf("KeepAlive timeout should be greater than or equal to 0, now - %d\n", KeepAliveTimeout) diff --git a/router/timer.go b/router/timer.go index 3c7eeb2e..54e66cc7 100644 --- a/router/timer.go +++ b/router/timer.go @@ -15,7 +15,7 @@ type timerSinceCtxKey = struct{} func startRequestTimer(r *http.Request) (*http.Request, context.CancelFunc) { ctx := r.Context() ctx = context.WithValue(ctx, timerSinceCtxKey{}, time.Now()) - ctx, cancel := context.WithTimeout(ctx, time.Duration(config.WriteTimeout)*time.Second) + ctx, cancel := context.WithTimeout(ctx, time.Duration(config.Timeout)*time.Second) return r.WithContext(ctx), cancel } diff --git a/server.go b/server.go index 7c06a3f1..dd1968f9 100644 --- a/server.go +++ b/server.go @@ -59,7 +59,7 @@ func startServer(cancel context.CancelFunc) (*http.Server, error) { s := &http.Server{ Handler: buildRouter(), - ReadTimeout: time.Duration(config.ReadTimeout) * time.Second, + ReadTimeout: time.Duration(config.ReadRequestTimeout) * time.Second, MaxHeaderBytes: 1 << 20, ErrorLog: errLogger, }