Skip to content

reverseproxy: Fix health_port being ignored in health checks#7533

Merged
francislavoie merged 2 commits intocaddyserver:masterfrom
akindemirci:master
Mar 3, 2026
Merged

reverseproxy: Fix health_port being ignored in health checks#7533
francislavoie merged 2 commits intocaddyserver:masterfrom
akindemirci:master

Conversation

@akindemirci
Copy link
Contributor

@akindemirci akindemirci commented Feb 27, 2026

Fix #7524

Assistance Disclosure

"I used Claude Sonnet 4.6 for identifying and fixing the bug, then I tested the compiled binary."

@CLAassistant
Copy link

CLAassistant commented Feb 27, 2026

CLA assistant check
All committers have signed the CLA.

@mholt
Copy link
Member

mholt commented Feb 27, 2026

Thanks. Can your LLM add a test case?

Annnd... ideally, explain when/why it broke?

@francislavoie francislavoie added the bug 🐞 Something isn't working label Feb 27, 2026
@francislavoie francislavoie added this to the v2.11.2 milestone Feb 27, 2026
@francislavoie francislavoie changed the title fix for ignoring health_port reverseproxy: Fix health_port being ignored in health checks Feb 27, 2026
@akindemirci
Copy link
Contributor Author

I made my LLM add a test case.

I really couldn't understand the algorithm behind the code. It's best to paste what LLM figured out:

Bug

Commit 6c38ae73 introduced health_upstream support. To populate DialInfo.Upstream,
it replaced the old code (which built DialInfo directly from the already port-adjusted
addr) with fillDialInfo called on the original upstream. This caused fillDialInfo
to re-parse upstream.Dial from scratch — discarding the health port that had already
been applied to addr. The transport then used dialInfo.Address (original port) to
dial, ignoring the URL host (correct port).

Fix

Added an else if branch in doActiveHealthCheckForAllHosts: when health_port is set,
build dialInfoUpstream using addr.JoinHostPort(0) — which already has the health port
baked in — so fillDialInfo produces the correct dialInfo.Address.

} else if upstream.activeHealthCheckPort != 0 {
    // health_port overrides the port; addr has already been updated
    // with the health port, so use its address for dialing
    dialInfoUpstream = &Upstream{
        Dial: addr.JoinHostPort(0),
    }
}

Copy link
Member

@francislavoie francislavoie left a comment

Choose a reason for hiding this comment

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

Thanks!

@francislavoie francislavoie merged commit 11b56c6 into caddyserver:master Mar 3, 2026
27 checks passed
@github-actions github-actions bot mentioned this pull request Mar 6, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐞 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

health_port is ignored

4 participants