Skip to content

reverseproxy: close connection on proxy protocol error paths#7836

Open
Ackberry wants to merge 3 commits into
caddyserver:masterfrom
Ackberry:fix/reverseproxyConnLeak
Open

reverseproxy: close connection on proxy protocol error paths#7836
Ackberry wants to merge 3 commits 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.

@steadytao steadytao changed the title reverseproxy: close connection on proxy protocol error paths" -m "Aft… reverseproxy: close connection on proxy protocol error paths Jun 28, 2026
@Ackberry

Copy link
Copy Markdown
Author

Hey @steadytao , just wanted to remind you of this PR!

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry this took me a while. The close calls are in the right places from what I can see but please add a regression test proving that an established connection is closed when proxy-protocol setup fails.

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The requested regression test is still missing; please add one proving that the established connection is closed when proxy-protocol setup fails.

@Ackberry

Copy link
Copy Markdown
Author

sorry took a while. On it now.

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.

3 participants