From 9c88625e25c9ca5debce728b9360c32f1acd1210 Mon Sep 17 00:00:00 2001 From: kshitij Date: Tue, 4 Aug 2026 11:09:59 +0530 Subject: [PATCH] fix(gateway): bound go_dormant ws.close with teardown timeout Sibling site to the disconnect() fix: go_dormant() still did an unbounded await self._ws.close(), the exact same pattern bounded in disconnect(). go_dormant runs on the scale-to-zero suspend path (Fly autostop), which also has timeout constraints. Apply the same 1s wait_for treatment using _TEARDOWN_AWAIT_TIMEOUT_S. Found during review of PR #78027. --- gateway/relay/ws_transport.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gateway/relay/ws_transport.py b/gateway/relay/ws_transport.py index 442453ab74b7f..07981a327e720 100644 --- a/gateway/relay/ws_transport.py +++ b/gateway/relay/ws_transport.py @@ -670,9 +670,11 @@ class WebSocketRelayTransport: # flip us back to a fast reconnect. self._dormant = True try: - await self._ws.close() - except Exception: # noqa: BLE001 - best-effort; the reader still ends + arms reconnect - logger.debug("relay go_dormant: ws.close() raised", exc_info=True) + await asyncio.wait_for( + self._ws.close(), timeout=_TEARDOWN_AWAIT_TIMEOUT_S + ) + except (asyncio.TimeoutError, Exception): # noqa: BLE001 - best-effort; the reader still ends + arms reconnect + logger.debug("relay go_dormant: ws.close() raised or timed out", exc_info=True) return acked async def _send_inbound_ack(self, buffer_id: str) -> None: