fix: wait for req socket send to make sure we dont stay stuck - if there's no... #23

Merged
9828273 merged 19 commits from feat/cb2ui-robot-connections into dev 2025-11-18 12:24:15 +00:00
Showing only changes of commit ca8b57fec5 - Show all commits

View File

@@ -47,7 +47,7 @@ async def ping_stream(request: Request):
sub_socket.setsockopt(zmq.SUBSCRIBE, b"ping")
connected = False
ping_frequency = 1 # How many seconds between ping attempts
ping_frequency = 2
# Even though its most likely the updates should alternate
# So, True - False - True - False for connectivity.
@@ -58,9 +58,10 @@ async def ping_stream(request: Request):
topic, body = await asyncio.wait_for(
sub_socket.recv_multipart(), timeout=ping_frequency
)
logger.debug("got ping change in ping_stream router")
logger.debug(f"got ping change in ping_stream router: {body}")
connected = json.loads(body)
except TimeoutError:
logger.debug("got timeout error in ping loop in ping router")
await asyncio.sleep(0.1)
# Stop if client disconnected
@@ -69,7 +70,7 @@ async def ping_stream(request: Request):
break
logger.debug(f"Yielded new connection event in robot ping router: {str(connected)}")
falseJson = json.dumps(connected)
yield (f"data: {falseJson}\n\n")
connectedJson = json.dumps(connected)
yield (f"data: {connectedJson}\n\n")
return StreamingResponse(event_stream(), media_type="text/event-stream")