Repository navigation
fix: parse IPv6 Sentinel URL nodes independently - #781
Open
Claire-ovo wants to merge 1 commit into
Open
Claire-ovo wants to merge 1 commit into
Claire-ovo wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.