mirror of
https://github.com/caddyserver/caddy.git
synced 2026-11-24 00:40:03 +00:00
* reverseproxy: close backend body and hijacked socket on upgrade setup failures When an upstream response indicates an HTTP upgrade (101 Switching Protocols), handleUpgradeResponse takes ownership of res.Body and subsequently hijacks the client connection. However, if any setup check fails prior to starting handleUpgradeTunnel (such as mismatched upgrade headers, non-writable body assertion failure, hijack unsupported, or handshake buffer flush errors), the function returned early without closing res.Body or the hijacked client socket. Because calling Hijack() permanently disables net/http's automatic connection cleanup, and raw TCP sockets are not closed by the garbage collector, these early failure exits leaked file descriptors into CLOSE_WAIT/ESTABLISHED. Fix this by: 1. Adding a deferred cleanup guard that closes res.Body and any hijacked front connection unless the tunnel successfully takes ownership. 2. Wrapping connections with onceCloseConn to ensure idempotent closure while preserving optional CloseWrite (TCP half-close) support. 3. Adding TestUpgradeResponseCleanupOnFailure to verify cleanup. * reverseproxy: test post-hijack cleanup and remove once-close wrappers Cover handshake flush and buffered backend-write failures after successful hijacking, checking that both connections close. Keep setup-failure cleanup while using the original connections directly. Code and tests were AI-assisted using an OpenAI coding assistant in Pi. |
||
|---|---|---|
| .. | ||
| fastcgi | ||
| forwardauth | ||
| active_health_test.go | ||
| addresses.go | ||
| addresses_test.go | ||
| admin.go | ||
| admin_test.go | ||
| ascii.go | ||
| ascii_test.go | ||
| buffering_test.go | ||
| caddyfile.go | ||
| client_disconnect_test.go | ||
| command.go | ||
| copyresponse.go | ||
| dynamic_upstreams_test.go | ||
| extended_connect_test.go | ||
| headers_test.go | ||
| healthchecks.go | ||
| hopheaders_test.go | ||
| hosts.go | ||
| httptransport.go | ||
| httptransport_test.go | ||
| incremental_test.go | ||
| metrics.go | ||
| metrics_test.go | ||
| passive_health_test.go | ||
| prepare_request_bench_test.go | ||
| request_trailers_test.go | ||
| retries_test.go | ||
| reverseproxy.go | ||
| selectionpolicies.go | ||
| selectionpolicies_test.go | ||
| streaming.go | ||
| streaming_test.go | ||
| tracing_test.go | ||
| upstreams.go | ||
| upstreams_bench_test.go | ||
| upstreams_test.go | ||
| webtransport_pump.go | ||
| webtransport_pump_test.go | ||
| webtransport_transport.go | ||
| webtransport_transport_test.go | ||