From da170f8ae7c326a101ae7b50f43f5e46d131b376 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Mon, 5 Oct 2026 10:33:03 +0200 Subject: [PATCH] serve: /config and /load bodies are marked read, so the close does not wait for the drain (#594) --- serve/server.py | 3 ++- serve/test_server.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/serve/server.py b/serve/server.py index 62305b1e3..b8067f15c 100644 --- a/serve/server.py +++ b/serve/server.py @@ -3435,6 +3435,7 @@ def make_handler(svc: Service): complete = False finally: self.connection.settimeout(timeout) + self.body_read = True # nothing left for the drain to wait for (#594) if not complete: self._json(400, {"error": {"message": "incomplete control request body"}}) return complete @@ -3465,7 +3466,7 @@ def make_handler(svc: Service): def _config_post(self): """#564: change a few documented keys of the run config - JSON from Strata's own page only, as /settings (the key is checked before); every other key of the file stays as it is.""" - body = self.rfile.read(int(self.headers.get("Content-Length", 0))) + body = self._body() if not self._own_page("the run config can be changed"): return if not svc.config_path: diff --git a/serve/test_server.py b/serve/test_server.py index f5c1d445e..f1d70a285 100644 --- a/serve/test_server.py +++ b/serve/test_server.py @@ -3090,6 +3090,14 @@ class AnswerBeforeTheBody(unittest.TestCase): def test_not_the_apps_own_page(self): self.assertEqual(self.status("POST", "/load", {"Origin": "https://example.com"}), "HTTP/1.0 403 Forbidden") + def test_a_body_a_handler_read_is_not_waited_for(self): + """#594: /config and /load read their body themselves: the close must not wait for the drain's 5 s.""" + for path in ("/config", "/load", "/unload"): + with self.subTest(path=path): + t0 = time.monotonic() + self.status("POST", path) + self.assertLess(time.monotonic() - t0, 1.5) # the status() helper itself pauses 0.5 s + def test_a_host_the_server_does_not_answer_to(self): self.assertEqual(self.status("POST", "/v1/chat/completions", {"Host": "rebind.example.com"}), "HTTP/1.0 403 Forbidden")