⚠️ Potential issue | 🟡 Minor
Signal handlers set via signal.signal() won't interrupt blocking ws.recv().
When SIGTERM/SIGINT is received, _stop_event is set, but ws.recv() at line 428 blocks indefinitely until a message arrives. The adapter won't shut down gracefully until the next WebSocket message is received.
Proposed fix: Use asyncio.wait_for with timeout
try:
while not self._stop_event.is_set():
- incoming = await ws.recv()
+ try:
+ incoming = await asyncio.wait_for(ws.recv(), timeout=5.0)
+ except asyncio.TimeoutError:
+ continue
event = json.loads(incoming)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@integrations/openclaw/openclaw_gateway_adapter.py` around lines 400 - 404,
The current signal handlers set self._stop_event but the blocking await
ws.recv() call (ws.recv()) prevents noticing that flag; replace the plain await
ws.recv() with an asyncio.wait_for wrapper (e.g., await
asyncio.wait_for(ws.recv(), timeout=1.0)) inside the receive loop, catch
asyncio.TimeoutError to loop back and check self._stop_event.is_set(), and only
process messages when recv returns; also ensure the stop_handler still sets
self._stop_event so the loop can exit promptly when the timeout loop observes
it.
Originally posted by @coderabbitai in #27 (comment)
Signal handlers set via
signal.signal()won't interrupt blockingws.recv().When
SIGTERM/SIGINTis received,_stop_eventis set, butws.recv()at line 428 blocks indefinitely until a message arrives. The adapter won't shut down gracefully until the next WebSocket message is received.Proposed fix: Use asyncio.wait_for with timeout
try: while not self._stop_event.is_set(): - incoming = await ws.recv() + try: + incoming = await asyncio.wait_for(ws.recv(), timeout=5.0) + except asyncio.TimeoutError: + continue event = json.loads(incoming)🤖 Prompt for AI Agents
Originally posted by @coderabbitai in #27 (comment)