From 2f461b75bf587fd6e107fc1a146cd23043be1b80 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sun, 18 Oct 2026 09:51:34 +0200 Subject: [PATCH] fix(healthcheck): end the probe request at the header terminator The generated tcp and http_status probes built their request with echo -e, and echo appends a newline, so the bytes on the wire ended with a stray bare LF after the header terminator of a Connection: close request. uvicorn's h11 reader treats that as trailing data and answers 400 before the handler's 200 reaches the socket, so the probe's grep for a 2xx or 3xx status line never matched and the container stayed unhealthy for good. In compose the name resolves straight to the container, so an unhealthy but running service still served and only the backup drill noticed, failing with litellm is running/unhealthy after 1200s. In swarm a task joins the service VIP only once it is healthy, so the litellm service sat at 0/1 with no backend and every consumer of http://litellm:4000 got ECONNREFUSED, which is where the openwebui model publishing died. The tcp flavor had been masking the same malformed request all along, because its grep for HTTP/1 matches 400 Bad Request as happily as 200. printf is a bash builtin like echo and the probe already requires bash for /dev/tcp, so nothing new is demanded of the image. The new test runs the generated request through bash and compares the bytes. Co-Authored-By: Claude Opus 5 (1M context) --- tests/unit/python/utils/docker/test_healthcheck.py | 13 ++++++++++++- utils/docker/healthcheck/probes.py | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/unit/python/utils/docker/test_healthcheck.py b/tests/unit/python/utils/docker/test_healthcheck.py index bf60848151..bf3cd097a7 100644 --- a/tests/unit/python/utils/docker/test_healthcheck.py +++ b/tests/unit/python/utils/docker/test_healthcheck.py @@ -125,9 +125,20 @@ class TestOtherFlavors(unittest.TestCase): self.assertIn("grep -q 'HTTP/1'", argv[3]) def test_tcp_keeps_the_escapes_the_shell_needs(self): - """echo -e must receive backslash escapes, not real newlines.""" + """printf must receive backslash escapes, not real newlines.""" self.assertIn("\\r\\n", probe("tcp", port=80)[3]) + def test_the_request_stops_at_the_header_terminator(self): + """A trailing LF makes uvicorn's h11 reader answer 400, not the handler.""" + with tempfile.TemporaryDirectory() as tmp: + sent = Path(tmp) / "request" + script = f"exec 3>{sent}\n{Tcp(port=80, path='health').request()}" + subprocess.run(["bash", "-c", script], check=True) + self.assertEqual( + b"GET /health HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n", + sent.read_bytes(), + ) + def test_http_status_demands_a_2xx_or_3xx_status_line(self): argv = probe("http_status", port=80, path="health") self.assertIn("GET /health HTTP/1.1", argv[3]) diff --git a/utils/docker/healthcheck/probes.py b/utils/docker/healthcheck/probes.py index 837878bbf8..fe8c7b6c72 100644 --- a/utils/docker/healthcheck/probes.py +++ b/utils/docker/healthcheck/probes.py @@ -27,7 +27,7 @@ TIMING_DEFAULTS: dict[str, object] = { } _HTTP_REQUEST = ( - "echo -e 'GET /{path} HTTP/1.1\\r\\nHost: localhost\\r\\n" + "printf 'GET /{path} HTTP/1.1\\r\\nHost: localhost\\r\\n" "Connection: close\\r\\n\\r\\n' >&3" )