From 06f233925b3e8dd078d212d5238c71269042d0eb Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 17 Sep 2026 00:44:19 +0100 Subject: [PATCH] fix: refuse a Redis URL on port zero parts.port returns 0 rather than raising, since 0 is inside the range it checks, so the URL reached .env and the worker and cache had nothing to connect to. --- docsgpt/deploy/commands.py | 8 +++++++- tests/deploy/test_native.py | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docsgpt/deploy/commands.py b/docsgpt/deploy/commands.py index db114639..0d95655f 100644 --- a/docsgpt/deploy/commands.py +++ b/docsgpt/deploy/commands.py @@ -216,12 +216,18 @@ def _redis_urls(base: str) -> dict[str, str]: # urlsplit raises on things like redis://[::1 ; that is a typo, not a crash. raise DeployError(f"the Redis URL {base!r} could not be read: {exc}") from exc try: - _ = parts.port # a non-numeric or out-of-range port raises here, not when the URL is split + port = parts.port # a non-numeric or out-of-range port raises here, not when the URL is split except ValueError as exc: raise DeployError( f"the Redis URL {base!r} has an unusable port: {exc}. Pass a URL like " "redis://host:6379 or redis://host:6379/5." ) from exc + if port == 0: + # urlsplit is happy with it, since 0 is inside the range, but nothing can connect to it. + raise DeployError( + f"the Redis URL {base!r} has an unusable port: 0. Pass a URL like " + "redis://host:6379 or redis://host:6379/5." + ) if parts.scheme not in ("redis", "rediss"): raise DeployError( f"the Redis URL {base!r} should start with redis:// or rediss://, with any options as " diff --git a/tests/deploy/test_native.py b/tests/deploy/test_native.py index a9335068..3c6341f7 100644 --- a/tests/deploy/test_native.py +++ b/tests/deploy/test_native.py @@ -231,7 +231,8 @@ class TestNativeUp: with pytest.raises(DeployError, match="too long to read"): _run(argv, _native_context()) - @pytest.mark.parametrize("url", ["redis://localhost:notaport/0", "redis://localhost:65536/0"]) + @pytest.mark.parametrize("url", ["redis://localhost:notaport/0", "redis://localhost:65536/0", + "redis://localhost:0/0"]) def test_a_redis_url_with_an_unusable_port_is_refused(self, tmp_path, url): """urlsplit accepts it and rebuilds it verbatim; only .port notices, and the worker dies later.""" argv = ["up", "--native", "--dir", str(tmp_path), "--yes",