Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/control_plane/canonical_authority_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from collections import deque
import json
import os
import queue
from datetime import datetime
from pathlib import Path
import selectors
Expand All @@ -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
Expand Down Expand Up @@ -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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Windows 队列超时后会把上一条响应交给下一请求。在真实 Node 子进程上仅选择新 Windows 队列分支,令第一条请求超过期限、随后才写出响应。队列抛出 Empty,worker 留在原进程。下一请求收到上次超时的响应。本机观测覆盖 Python 队列和 OS 管道,Windows 原生跑法仍以作者记录为依据。 把 queue.Empty 归一到 worker 的既有超时关闭或重建路径,确保超时进程结束后才可消费新响应。读取线程捕获本代队列,补上延迟响应和下一轮实际返回值的回归覆盖。

if line is None:
raise EOFError("canonical authority worker closed stdout")
return line
chunks = bytearray()
selector = selectors.DefaultSelector()
selector.register(stdout, selectors.EVENT_READ)
Expand Down
Loading