mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 14:30:52 +00:00
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) <noreply@anthropic.com>
This commit is contained in:
1 parent
12ed8a763c
commit
2f461b75bf
2 files changed
+13
-2
No files matched your search
@@ -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])
|
||||
|
||||
Reference in new issue
Block a user