From fc9e84a099e10bb8611b2bbdce671e6d8b87ff50 Mon Sep 17 00:00:00 2001 From: ldm0 Date: Sat, 17 Oct 2026 23:45:19 +0800 Subject: [PATCH] fix(wpt): absorb parallel fixture connection bursts The inherited listen backlog of five makes concurrent browser connections wait for TCP retries before fixture handlers run. Match wptserve's backlog of 2000 for every IPv4/IPv6 origin without changing test timeouts. Add real socket tests that queue a complete 50-worker burst before the accept loop starts. Both address families time out before this change and connect successfully afterward. With the same frozen release binary, Worker error stress changes from 86/100 passes to 150/150 after changing only the backlog. Script-order and worker XHR timing cases each pass all 30 additional trials. Validation: 81 Python tests across connection backlog, fixture resources, fixture responses and runner orchestration; git diff --check. --- .../moli_benchmark/wpt_cross/server.py | 5 +++ .../tests/test_wpt_connection_backlog.py | 39 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 moli-benchmark/tests/test_wpt_connection_backlog.py diff --git a/moli-benchmark/moli_benchmark/wpt_cross/server.py b/moli-benchmark/moli_benchmark/wpt_cross/server.py index bb22c9abff..02fb951e4b 100644 --- a/moli-benchmark/moli_benchmark/wpt_cross/server.py +++ b/moli-benchmark/moli_benchmark/wpt_cross/server.py @@ -1847,6 +1847,11 @@ def _wpt_cookie_websocket_set_cookie(query: str) -> str | None: class _FixtureThreadingHTTPServer(ThreadingHTTPServer): + # Match wptserve: parallel browsers open bursts of subresource connections. + # The stdlib backlog of five makes them wait for TCP retransmissions before + # their requests reach a handler, changing the timing the cases measure. + request_queue_size = 2000 + def handle_error(self, request: object, client_address: object) -> None: # Disposing a case BrowserContext intentionally cancels any auxiliary # requests that outlive the harness result. The stdlib server prints a diff --git a/moli-benchmark/tests/test_wpt_connection_backlog.py b/moli-benchmark/tests/test_wpt_connection_backlog.py new file mode 100644 index 0000000000..43a0441947 --- /dev/null +++ b/moli-benchmark/tests/test_wpt_connection_backlog.py @@ -0,0 +1,39 @@ +from __future__ import annotations + +import socket +import unittest +from contextlib import ExitStack, closing +from http.server import BaseHTTPRequestHandler + +from moli_benchmark.wpt_cross.server import ( + _FixtureThreadingHTTPServer, + _Ipv6ThreadingHTTPServer, +) + + +class FixtureConnectionBacklogTests(unittest.TestCase): + def assert_worker_burst_can_connect( + self, + server_class: type[_FixtureThreadingHTTPServer], + address: tuple[str, int], + ) -> None: + # Hold the accept loop so all connections coexist in the listen queue. + # This isolates queue capacity from handler speed and TCP retry timing. + with server_class(address, BaseHTTPRequestHandler) as server: + host, port = server.server_address[:2] + with ExitStack() as connections: + for _ in range(50): + connections.enter_context(closing(socket.create_connection( + (host, port), timeout=1, + ))) + + def test_loopback_listener_accepts_a_full_worker_burst(self) -> None: + self.assert_worker_burst_can_connect( + _FixtureThreadingHTTPServer, ("127.0.0.1", 0), + ) + + @unittest.skipUnless(socket.has_ipv6, "IPv6 is unavailable") + def test_ipv6_listener_accepts_a_full_worker_burst(self) -> None: + self.assert_worker_burst_can_connect( + _Ipv6ThreadingHTTPServer, ("::1", 0), + )