Skip to content

reverseproxy: close connection on proxy protocol error paths" -m "Aft…#7836

Open
Ackberry wants to merge 1 commit into
caddyserver:masterfrom
Ackberry:fix/reverseproxyConnLeak
Open

reverseproxy: close connection on proxy protocol error paths" -m "Aft…#7836
Ackberry wants to merge 1 commit into
caddyserver:masterfrom
Ackberry:fix/reverseproxyConnLeak

Conversation

@Ackberry

Copy link
Copy Markdown

Assistance Disclosure

AI was used. I used Claude Code to help draft PR message and understand the codebase. I worked as a peer-programmer.

What this does

In HTTPTransport's custom dialContext closure (modules/caddyhttp/reverseproxy/httptransport.go), the connection is established via dialer.DialContext and then, when proxy_protocol is configured, several error paths returned without closing the already-open connection, leaking the socket:

  • missing proxy protocol info from context
  • unrecognized proxy protocol version
  • unexpected remote addr type in proxy protocol info
  • failure writing the proxy protocol header to the connection

This closes conn on each of those paths. The dial-failure return (where no connection exists yet) and the success path are unchanged.

Addresses the reverse proxy item in #7833. Per the maintainer's suggestion in that issue, the other reported leaks are left for separate PRs by area.

Testing

  • go build ./...
  • go test -race ./modules/caddyhttp/reverseproxy/ passes

…er a successful dial, the four error returns in the ProxyProtocol

block of dialContext returned without closing the established
connection, leaking the socket. Close conn on each path.

Fixes one item from caddyserver#7833."

Signed-off-by: Ackberry <akbari@usf.edu>
@CLAassistant

CLAassistant commented Jun 23, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants