Skip to content

fix: resolve the ?addr=:port shorthand against the primary host - #1025

Merged
rueian merged 2 commits into
redis:mainfrom
NotAFlightRisk:fix/parseurl-addr-port-shorthand
Aug 30, 2026
Merged

rueian merged 2 commits into
redis:mainfrom
NotAFlightRisk:fix/parseurl-addr-port-shorthand

Conversation

@NotAFlightRisk

@NotAFlightRisk NotAFlightRisk commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Running two Redis instances on one box is common enough, and ?addr=:6380 is the shorthand for pointing at the second one. Do that against a primary that has its own port and you get back an address nothing can dial:

rueidis.ParseURL("redis://cache:6379?addr=:6380")
// InitAddress: ["cache:6379", "[cache:6379]:6380"]

Thats v1.0.77. A port-only ?addr= has no host of its own, so it falls back to u.Host, which still carries the primarys :6379, and the whole thing gets bracketed as though it were an IPv6 literal. It only goes wrong when the primary has an explicit port, so nearly always. And because it fails at connect time rather than at parse time, it reads like DNS or a firewall.

Giving that fallback the host the primary already resolved to leaves the primary address and the TLS ServerName alone. I diffed the parse output over a spread of URLs, bracketed and unbracketed IPv6 and unix:// included, and only the ?addr= entries move. ?addr=host with no port I've left alone, its still resolving to the primary's host insted of host:6379. Most of the diff is the two test cases, copying the shape of the ?addr= assertion above them.


Note

Low Risk
Small, localized change to Redis URL parsing with targeted tests; wrong addresses fail at dial time but do not affect security-sensitive paths.

Overview
Fixes broken multi-instance Redis URLs when the primary includes an explicit port and extra nodes use the ?addr=:port shorthand (e.g. redis://cache:6379?addr=:6380).

In ParseURL’s parseAddr helper, the host fallback for port-only addr values now uses u.Hostname() instead of u.Host, so the resolved host is cache (or [::1] for IPv6) rather than the full host:port string that was incorrectly joined and bracketed as [cache:6379]:6380. Primary address and TLS ServerName behavior stay the same; only ?addr= entries that omit a host change.

Tests cover hostname+port and bracketed IPv6 primaries with ?addr=:6380.

Reviewed by Cursor Bugbot for commit 28879b5. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread url.go Resolved
Comment thread url.go Resolved
Comment thread url.go Resolved
@rueian
rueian merged commit 2ed2326 into redis:main Aug 30, 2026
28 of 29 checks passed
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