From 2675fc53a211175e7b8e577f8e458263df1d5e26 Mon Sep 17 00:00:00 2001 From: Marco Bambini Date: Fri, 18 Sep 2026 08:23:08 +0200 Subject: [PATCH] The server's listen backlog was socketserver's default of 5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TestConcurrency sends 8 requests at once, and every request holds the engine lock for a whole generation, so the connects all land before the accept loop drains them. With a backlog of 5 the surplus was reset, and on macOS 27 the test failed 11 of 20 runs with ECONNRESET, broken pipes and 5-7 of 8 answers. ChatServer now sets request_queue_size = 128, the default kern.ipc.somaxconn a larger value would be clipped to: 0 of 30 after, and make serve-check passes (319 tests, 23 skipped). The kernel's own counter did not confirm the overflow — netstat's "listen queue overflow" stayed at 0 across failing runs, apparently because loopback is not counted there — so the evidence is the failure rate, not the counter. Also CLAUDE.md: `-t .` is a `discover` option, and Python 3.14 rejects it on a single-module run ("unrecognized arguments"). Dropped from the test_regions and test_xtml.TestAgainstUpstream commands, kept on discover. Co-Authored-By: Claude Opus 5 --- CLAUDE.md | 4 ++-- serve/server.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index f91089772..015a9d171 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -108,8 +108,8 @@ WASTE_BACKEND=cpu WASTE_DUMP_ROUTE=b.route ./test_forward M IDS b.bin 0 tests/route_diff.py --ref a.route --other b.route --scores a.scores python3 -m unittest discover -s tests/serve -t . -p "test_*.py" # all serve tests -python3 -m unittest tests.serve.test_regions -t . # one module -K3_DIR=... python3 -m unittest tests.serve.test_xtml.TestAgainstUpstream -t . +python3 -m unittest tests.serve.test_regions # one module (-t is discover-only) +K3_DIR=... python3 -m unittest tests.serve.test_xtml.TestAgainstUpstream K2_DIR=... uv run --with jinja2 python -m unittest tests.serve.test_chatfmt_upstream ``` diff --git a/serve/server.py b/serve/server.py index 6d50be688..1f83ac849 100644 --- a/serve/server.py +++ b/serve/server.py @@ -58,6 +58,13 @@ class ChatServer(ThreadingHTTPServer): daemon_threads = True allow_reuse_address = True + # socketserver's listen backlog is 5. Every request holds the engine + # lock for a whole generation, so clients arrive in bursts that all + # connect before the accept loop drains them, and a burst of 8 (what + # TestConcurrency sends) overflowed it: macOS 27 answered the surplus + # connects with a reset, and the test failed about half its runs. 128 + # is macOS's default somaxconn, so a larger value would be clipped. + request_queue_size = 128 def __init__(self, addr, handler, *, engine: Engine, model_id: str, api_key: Optional[str] = None,