oauth2-proxy/pkg/upstream
Mateen Anjum c2a5dfa4ea
feat(upstream): add configurable transport buffer sizes for large uploads
Large PUT/POST uploads (>60MB) fail with context canceled when an nginx
reverse proxy sits in front of oauth2-proxy. The root cause is that
http.Transport inherits Go's default 4KB WriteBufferSize, requiring
~15,000 write syscalls for a 60MB upload. This generates backpressure
on the nginx->oauth2-proxy pipe. Once nginx hits proxy_read_timeout
between consecutive write ops, it closes the connection, canceling
req.Context(), which propagates as context canceled on the in-flight
RoundTrip to the upstream.

Expose writeBufferSize and readBufferSize on the Upstream config struct,
wired to transport.WriteBufferSize and transport.ReadBufferSize in
newReverseProxy. Both default to 0 (preserving current behavior, Go
uses 4KB). Setting writeBufferSize to 65536 (64KB) reduces write
syscalls by 16x and resolves the timeout correlation for large uploads.

Fixes #3389

Signed-off-by: Mateen Anjum <mateenali66@gmail.com>
2026-03-29 05:48:01 -04:00
..
file.go Don't use http.StripPrefix when a file: upstream has rewriteTarget 2024-09-02 11:27:28 +01:00
file_test.go Don't use http.StripPrefix when a file: upstream has rewriteTarget 2024-09-02 11:27:28 +01:00
http.go feat(upstream): add configurable transport buffer sizes for large uploads 2026-03-29 05:48:01 -04:00
http_test.go feat(upstream): add configurable transport buffer sizes for large uploads 2026-03-29 05:48:01 -04:00
proxy.go fix: propagate errors during route building (#3383) 2026-03-23 11:25:20 +01:00
proxy_test.go fix: propagate errors during route building (#3383) 2026-03-23 11:25:20 +01:00
rewrite.go fix: websocket path rewrite (#2300) 2024-11-04 23:12:35 +01:00
rewrite_test.go fix: websocket path rewrite (#2300) 2024-11-04 23:12:35 +01:00
static.go deref everything but now with default constants 2025-11-16 22:38:56 +01:00
static_test.go chore(deps): Updated to ginkgo v2 (#2459) 2024-07-18 22:41:02 +02:00
upstream_suite_test.go fix: WebSocket proxy to respect PassHostHeader setting (#3290) 2026-01-16 20:30:16 +01:00