Repository navigation
fix: parse IPv6 Sentinel URL nodes independently - #781
Claire-ovo wants to merge 1 commit into
Conversation
chrikrah
left a comment
There was a problem hiding this comment.
@Claire-ovo, the per-node parse fixes the IPv6 cases, but one rejection depends on the patch release.
# git archive a4a835e, base 1188d0a, uv sync --frozen, --noconftest (the conftest starts docker compose)
$ uv run pytest -q --noconftest tests/unit/test_sentinel_url.py
Python 3.13.15: 39 passed
Python 3.12.6: 1 failed, 38 passed
FAILED test_parse_invalid_sentinel_hosts[[::1]suffix:26380]
$ python -c "from urllib.parse import urlparse; print(urlparse('//[::1]suffix:26380').hostname)"
3.10.21, 3.11.16, 3.13.15, 3.14.7: ValueError Invalid IPv6 URL
3.12.6: ::1 (port 26380)
# connection.py reverted to 1188d0a, tests kept (3.13.15): 21 failed, 18 passed
$ uv run black --check redisvl/redis/connection.py tests/unit/test_sentinel_url.py # black 26.5.1
2 files would be left unchanged.
blocking: your review record set the bracket check aside because 3.12.14 rejects this input. On 3.12.6 it returns ('::1', 26380), and requires-python allows that release. CI's "3.12" takes the latest patch, so CI can't show it. My pick is a check on host after the closing ], where only :<port> may follow. It holds on every release. Dropping that test case also works.
I'll re-run the suite on 3.12.6 once that check is in.
|
Hi, thanks for the PR - can you rebase your branch onto the latest |
vishal-bala
left a comment
There was a problem hiding this comment.
^ See my previous comment
Motivation
Sentinel URLs split each node on
:, so[::1]:26380becomes('[', 26379)rather than('::1', 26380). Parsing the entire comma-separated authority withurlparsealso rejects mixed hostname/IPv6 lists on current Python versions.Reproduce without a running server:
Changes
Separate the node list before URL parsing, then use the standard-library hostname/port parser for each node. Keep credential decoding, service/database selection, and the default Sentinel port; decode percent-encoded hostnames, including IPv6 scope identifiers.
Add parser regressions and parameter-forwarding coverage through sync, current async, and legacy async factories. Document bracketed IPv6 syntax. No dependency or query-parameter behavior changes.
Release Notes
Sentinel URLs accept bracketed IPv6 addresses and mixed hostname/IPv4/IPv6 lists. Empty nodes, unbracketed IPv6 and out-of-range ports now raise
ValueErrorduring parsing. Empty explicit ports and nonnumeric ports are also rejected, including on IPv6 nodes.Review record
Reviewed at
a4a835eadda2a665a9bb2618cf1b8ba9e5f4d446by Codex withpre-pr-review. Prepared with AI assistance; model identifier is not independently exposed by this execution environment.Lenses: correctness (parser/callers); security (connection URLs and credentials); design (shared factory behavior and legacy async compatibility); tests (new regressions); docs (IPv6 syntax). Lens passes were delegated; correctness/tests and design/docs reused their respective reviewer contexts. Final challenge ran in a fresh independent context. Skipped: Redis behaviour (no server command, reply or server-default change;
26379is the existing client default).redisvl/redis/connection.py:1067); added encoded/raw scope assertions. Added explicit port-zero and query/fragment boundary regressions.urlparse.Verified:
pytest tests/unit/test_sentinel_url.py tests/unit/test_connection_protocol.py tests/unit/test_connection_normalization.py -q -o log_cli=false --tb=short: 79 passed with the repository's Redis 8.4 Docker fixture enabled.pytest --noconftest tests/unit/test_sentinel_url.py -q -o log_cli=false --tb=short: 39 passed (pure parser/factory tests; no Docker fixture).[::1]:26380and through127.0.0.1:26381,[::1]:26380(first node deliberately unavailable). Sentinel and the discovered primary both bound to IPv6 loopback in an isolated container network namespace. This does not exercise failover.make format,make check-types(120 source files),pre-commit run code-quality-checks --all-files, andgit diff --check: passed.make docs-build: succeeded with 12 warnings in unchanged pages/dependency docstrings. Notebooks were not executed.Not checked: full repository suite, all Python/redis-py versions, Sentinel failover, TLS, authenticated live Sentinel, link-local interface connectivity, or Cluster behavior. Parser and mocked-factory tests do not prove those deployment scenarios.
Note
Medium Risk
Changes connection URL parsing for Sentinel deployments; incorrect parsing could block HA connections, though scope is limited to
_parse_sentinel_urland stricter validation may surface previously silent misconfigurations.Overview
Fixes
redis+sentinel://parsing so comma-separated Sentinel nodes are handled correctly when IPv6 literals use bracket notation or when hostnames and IPv6 addresses are mixed._parse_sentinel_urlno longer splits the authority on:or runs the whole list through a singleurlparse. It isolates the host list, parses each node with the stdlib hostname/port logic, keeps default port26379, and decodes percent-encoded hostnames (including IPv6 zone IDs). Malformed nodes (unbracketed IPv6, empty segments, invalid ports) now raiseValueErrorat parse time. Query strings and fragments are stripped from the authority so they cannot be mistaken for hosts or path segments.Unit tests cover valid IPv6/mixed lists, invalid inputs, and that sync, async, and legacy async factories still pass the parsed hosts, credentials, service name, and DB into
Sentinel/AsyncSentinel. Installation docs now describe bracketed IPv6 Sentinel URLs.Reviewed by Cursor Bugbot for commit a4a835e. Bugbot is set up for automated code reviews on this repo. Configure here.