From 64be16576493eae2c1cb793ff4691f30d8d97300 Mon Sep 17 00:00:00 2001 From: BigDataDZ <76271875+BigDataDZ@users.noreply.github.com> Date: Sun, 22 Nov 2026 11:04:59 +0800 Subject: [PATCH] fix(testing): read the canonical authority worker portably on Windows _read_line registered the worker's stdout pipe with selectors and selected on it. Windows select() only supports sockets, so every canonical-fixture setup failed natively with WinError 10038 and an empty stderr tail. Drain response lines from a daemon thread into a queue on Windows and keep the selector path unchanged on POSIX. Signed-off-by: BigDataDZ <76271875+BigDataDZ@users.noreply.github.com> --- .../canonical_authority_fixture.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/control_plane/canonical_authority_fixture.py b/tests/control_plane/canonical_authority_fixture.py index 57a7067c5d..97cc951cd5 100644 --- a/tests/control_plane/canonical_authority_fixture.py +++ b/tests/control_plane/canonical_authority_fixture.py @@ -11,6 +11,7 @@ from collections import deque import json import os +import queue from datetime import datetime from pathlib import Path import selectors @@ -35,6 +36,7 @@ def __init__(self, key: tuple[int, str, bool]) -> None: self.key = key self.call_lock = threading.Lock() self._stderr_tail: deque[str] = deque(maxlen=64) + self._line_queue: queue.SimpleQueue = queue.SimpleQueue() self._process = self._spawn(Path(key[1])) @staticmethod @@ -98,12 +100,36 @@ def _drain_stderr() -> None: pass threading.Thread(target=_drain_stderr, daemon=True).start() + # Windows select() supports sockets only; drain response lines from a + # thread instead of the selector-based pipe read in _read_line. + if os.name == "nt": + self._line_queue = queue.SimpleQueue() + + def _drain_lines() -> None: + try: + for raw_line in iter(proc.stdout.readline, b""): + self._line_queue.put(raw_line) + except OSError: + pass + finally: + self._line_queue.put(None) + + threading.Thread(target=_drain_lines, daemon=True).start() return proc def _read_line(self, timeout_seconds: float) -> bytes: stdout = self._process.stdout assert stdout is not None deadline = time.monotonic() + timeout_seconds + if os.name == "nt": + while True: + remaining = deadline - time.monotonic() + if remaining <= 0: + raise TimeoutError("canonical authority worker timed out waiting for response") + line = self._line_queue.get(timeout=remaining) + if line is None: + raise EOFError("canonical authority worker closed stdout") + return line chunks = bytearray() selector = selectors.DefaultSelector() selector.register(stdout, selectors.EVENT_READ)