Skip to content

The agent that grows with you

fix(gateway): bound the Windows control-pipe query at its own timeout

kshitijk4poord11d411f3370
diff --git a/gateway/control_socket.py b/gateway/control_socket.py
index c9626ee17e5..544e0df32f3 100644
--- a/gateway/control_socket.py
+++ b/gateway/control_socket.py
@@ -315,7 +315,17 @@ def _query_unix_socket(home: Path, request: bytes, timeout: float) -> Optional[b
return None
-def _query_windows_pipe(home: Path, request: bytes, timeout: float) -> Optional[bytes]: # pragma: no cover - wine2e lane
+def _query_windows_pipe(home: Path, request: bytes, timeout: float) -> Optional[bytes]:
+ """A synchronous pipe handle has no ``settimeout``: ``handle.read`` blocks until the peer answers,
+ so the ``deadline`` in ``_read_response_line`` is only checked between chunks. Run the exchange on
+ an abandoned-at-deadline worker so a peer that never answers costs ``timeout``, never forever —
+ the bound ``_query_unix_socket`` already gets from ``sock.settimeout`` (#132547)."""
+ from agent.deadline import run_bounded_sync
+ outcome = run_bounded_sync(lambda: _windows_pipe_exchange(home, request, timeout), timeout, label="control-pipe")
+ return None if outcome.timed_out else outcome.value
+
+
+def _windows_pipe_exchange(home: Path, request: bytes, timeout: float) -> Optional[bytes]: # pragma: no cover - wine2e lane
pipe_name = windows_pipe_name(home)
deadline = time.monotonic() + timeout
handle = None
diff --git a/tests/gateway/test_control_socket.py b/tests/gateway/test_control_socket.py
index 50b9758ea26..6e5f585a438 100644
--- a/tests/gateway/test_control_socket.py
+++ b/tests/gateway/test_control_socket.py
@@ -452,3 +452,32 @@ def test_runtime_inventory_prefers_socket_supervisor(tmp_path: Path, monkeypatch
# supervisor comes from the gateway's own declaration, not a PID scan
assert gws[0].supervisor == "systemd"
assert gws[0].code_sha == "SHA555"
+
+
+def test_windows_pipe_query_is_bounded_when_the_peer_never_answers(home: Path, monkeypatch):
+ """#132547: a pipe handle read cannot time out on its own; the query must still return None at its bound."""
+ import threading
+ import time
+
+ from gateway import control_socket
+
+ released = threading.Event()
+
+ class _SilentPipe: # accepts the request, never answers
+ def write(self, _data):
+ return None
+
+ def read(self, _n):
+ released.wait(10)
+ return b""
+
+ def close(self):
+ return None
+
+ monkeypatch.setattr(control_socket, "open", lambda *_a, **_k: _SilentPipe(), raising=False)
+ start = time.monotonic()
+ try:
+ assert control_socket._query_windows_pipe(home, b"{}\n", 0.3) is None
+ assert time.monotonic() - start < 2.0
+ finally:
+ released.set()