Skip to content

Commit b15fc33

Browse files
authored
feat(gateway): add idle-timeout setting for client connections (#371)
Add a new setting `gateway.config.idle-timeout` to configure the idle timeout for client connections in the Gateway. The default Caddy idle timeout is 5 minutes, which can be too short for long-running requests. This setting allows operators to increase the timeout for stacks that need longer request durations (e.g., Ledger bulk operations).
1 parent ba6b8e6 commit b15fc33

4 files changed

Lines changed: 21 additions & 0 deletions

File tree

docs/09-Configuration reference/01-Settings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ While we have some basic types (string, number, bool ...), we also have some com
6161
| gateway.ingress.tls.enabled | bool | true | Enable TLS if not enabled at Gateway CRD level |
6262
| gateway.caddyfile.trusted-proxies | string | 10.0.0.0/8,192.168.0.0/16 | Comma-separated list of IP ranges (CIDRs) of trusted proxy servers. Caddy will parse the real client IP from HTTP headers when requests come from these proxies. Use `private_ranges` to match all private IPv4 and IPv6 ranges. |
6363
| gateway.caddyfile.trusted-proxies-strict | bool | false | Enable strict (right-to-left) parsing of the X-Forwarded-For header. Recommended when using upstream proxies like HAProxy, Cloudflare, AWS ALB, or CloudFront. |
64+
| gateway.config.idle-timeout | string | 10m | Configure the idle timeout for client connections (default: 5m). Use Go duration format (e.g., 30s, 5m, 1h). |
6465

6566
### Postgres URI format
6667

internal/resources/gateways/Caddyfile.gotpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
{{- if .TrustedProxiesStrict }}
5353
trusted_proxies_strict
5454
{{- end }}
55+
{{- if .IdleTimeout }}
56+
timeouts {
57+
idle {{ .IdleTimeout }}
58+
}
59+
{{- end }}
5560
}
5661

5762
{{- if .Debug }}

internal/resources/gateways/caddyfile.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,10 @@ func withTrustedProxiesStrict() func(data map[string]any) error {
5454
return nil
5555
}
5656
}
57+
58+
func withIdleTimeout(timeout string) func(data map[string]any) error {
59+
return func(data map[string]any) error {
60+
data["IdleTimeout"] = timeout
61+
return nil
62+
}
63+
}

internal/resources/gateways/configuration.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ func createConfigMap(ctx core.Context, stack *v1beta1.Stack,
3030
options = append(options, withTrustedProxiesStrict())
3131
}
3232

33+
idleTimeout, err := settings.GetString(ctx, stack.Name, "gateway", "config", "idle-timeout")
34+
if err != nil {
35+
return nil, err
36+
}
37+
if idleTimeout != nil && *idleTimeout != "" {
38+
options = append(options, withIdleTimeout(*idleTimeout))
39+
}
40+
3341
caddyfile, err := CreateCaddyfile(ctx, stack, gateway, httpAPIs, broker, options...)
3442
if err != nil {
3543
return nil, err

0 commit comments

Comments
 (0)