Skip to content

Accept bracketed IPv6 hosts in --uri - #720

Merged
fcostaoliveira merged 2 commits into
masterfrom
fix-701-ipv6-uri
Oct 16, 2026
Merged

fcostaoliveira merged 2 commits into
masterfrom
fix-701-ipv6-uri

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Behaviour decision: --uri now accepts a bracketed IPv6 host, redis://[::1]:6379, the same RFC 3986 form that redis-cli -u accepts. The brackets are removed from the host. Malformed bracket forms are rejected during argument parsing. URIs without brackets are parsed exactly as before.

Problem

memtier_benchmark --uri="redis://[::1]:6379" fails with error: invalid port number ':1]:6379'. and exit code 1. redis://[::1]:6379/0 and redis://[::1] fail the same way. -s ::1 -p 6379 works, so only the URI path is affected (#701).

Root cause

parse_uri() split host and port with strchr(host_start, ':'), which finds the first : inside [::1]. Brackets were not handled anywhere, so even with a correct port split the host would have kept its [ and ].

Fix

In parse_uri(), if the host starts with [:

  • the host is everything up to the matching ], without the brackets;
  • the ] must be followed by :PORT or by nothing (the /db part is cut off earlier);
  • an unterminated [, empty [], or anything else after ] ([::1]x) is rejected with error: invalid IPv6 host '...' in URI. The message prints only the host part, so credentials from the URI are not echoed.

The port still goes through parse_port() from #699. The --help text for --uri now mentions the bracket form. The diff is limited to parse_uri(), one help line and the tests.

Tests

  • tests_oss_simple_flow.py::test_uri_ipv6_bracketed_host runs a short benchmark with --uri=redis://[::1]:PORT. It also passes decoy values, --server=host-must-be-overridden.invalid --port=1, with explicit_connect_args, so the run only succeeds if the URI really sets both the host and the port. It skips on unix-socket envs, on non-local hosts, and when [::1]:PORT is not reachable.
  • test_cli_validation_ports.py::test_uri_rejects_malformed_ipv6_host checks that [::1, [::1]x, [::1]x:6379, []:6379, [::1]:, [::1]:65537 and u:s3cret@[::1 are rejected with the right diagnostic, and that the password is never echoed to stderr.
  • test_cli_validation_ports.py::test_uri_accepts_ipv6_host_without_port checks that [::1], [::1]/0 and [::1]/ parse with no diagnostic and reach the connect stage against a refused port.

Measured locally on Redis 8.6.0. The RLTest-started server listens on ::1, so the connect test really ran and was not skipped:

binary live IPv6 test malformed test no-port test oss-cluster live test
origin/master bc7320a FAIL FAIL FAIL FAIL
this PR PASS (5/5) PASS (5/5) PASS (5/5) PASS
mutant A (bracketed host dropped) FAIL PASS PASS FAIL
mutant B (bracketed port ignored) FAIL FAIL PASS FAIL

All of test_cli_validation_ports.py passes 5/5 with this PR.

Manual matrix against redis-server --bind ::1 127.0.0.1:

URI master this PR
redis://[::1]:P invalid port number ':1]:P', rc=1 runs, rc=0
redis://[::1]:P/0 invalid port number, rc=1 runs, rc=0
redis://[::1] invalid port number ':1]', rc=1 connects to [::1]:6379 (default port)
redis://[::1 invalid port number ':1' invalid IPv6 host '[::1'
redis://[::1]x invalid port number ':1]x' invalid IPv6 host '[::1]x'
redis://[]:P "Name or service not known" at connect time invalid IPv6 host '[]:P'
redis://[::1]:99999 invalid port number ':1]:99999' invalid port number '99999'
redis://127.0.0.1:P rc=0 rc=0 (unchanged)

Fixes #701

Affected versions

2.2.0 through 2.5.2 (latest) and master.

🤖 Generated with Claude Code


Note

Low Risk
Scoped to URI argument parsing and validation; connection behavior for existing IPv4 URIs is unchanged.

Overview
Fixes --uri so bracketed IPv6 hosts work like redis-cli -u (e.g. redis://[::1]:6379), instead of treating the first : inside ::1 as the port separator.

parse_uri() now strips [/], finds the port only after ], and rejects malformed bracket syntax at parse time with error: invalid IPv6 host. IPv4 and unbracketed URIs behave as before. Help text documents the bracket form.

Tests cover a live benchmark on [::1] (with skips when unreachable) and CLI validation for bad IPv6 URI shapes and port errors.

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

fcostaoliveira and others added 2 commits October 16, 2026 14:56
parse_uri() split host and port at the first ':' after the credentials,
so redis://[::1]:6379 (the RFC 3986 form redis-cli -u accepts) failed
with "invalid port number ':1]:6379'". Brackets were not handled at all,
so the host would have kept its '[' ']' even with a correct port split.

When the host starts with '[', take everything up to the matching ']'
as the host (without brackets) and require ']' to be followed by ':PORT'
or nothing (the '/db' part is already cut off). An unterminated '[',
empty brackets, or trailing garbage after ']' is rejected with
"invalid IPv6 host". The port still goes through parse_port(), and
non-bracketed URIs are parsed exactly as before.

Fixes #701

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The live IPv6 test let mb.py add --server 127.0.0.1 --port <port>, so it
still passed if the URI dropped the bracketed host or ignored its port.
Pass explicit decoy --server/--port values that the URI has to override.
Assert that a rejected bracketed URI does not echo its password, and that
bracketed hosts without a port ([::1], [::1]/0, [::1]/) parse cleanly.
Mirror the new --help line in memtier_benchmark.1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira
fcostaoliveira merged commit 427d721 into master Oct 16, 2026
207 of 210 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.

--uri does not accept a bracketed IPv6 host (redis://[::1]:6379 fails with "invalid port number")

1 participant