Fix work recovery and reduce engine and chart overhead
Docs / docs (push) Successful in 33s
Playwright Tests / test-playwright (1, 2) (push) Failing after 1m37s
Playwright Tests / test-playwright (2, 2) (push) Failing after 27s
pre-commit / pre-commit (push) Failing after 2m37s
Test Backend / test-backend (3.12) (push) Successful in 5m7s
Test Backend / test-backend (3.14) (push) Successful in 5m2s
Compose Smoke Test / test-compose (push) Failing after 28s
Playwright Tests / merge-reports (push) Failing after 2m29s
Docs / docs (push) Successful in 33s
Playwright Tests / test-playwright (1, 2) (push) Failing after 1m37s
Playwright Tests / test-playwright (2, 2) (push) Failing after 27s
pre-commit / pre-commit (push) Failing after 2m37s
Test Backend / test-backend (3.12) (push) Successful in 5m7s
Test Backend / test-backend (3.14) (push) Successful in 5m2s
Compose Smoke Test / test-compose (push) Failing after 28s
Playwright Tests / merge-reports (push) Failing after 2m29s
This commit is contained in:
@@ -1700,8 +1700,8 @@ async def flow_events(websocket: WebSocket, ticket: str = "", token: str = "") -
|
||||
await websocket.send_text(orjson.dumps(payload).decode())
|
||||
return list(payload.get("demand", []))
|
||||
|
||||
async def catch_up() -> bool:
|
||||
"""Rescope a panel and send the snapshot again, demand included.
|
||||
async def rescope() -> bool:
|
||||
"""Recheck a panel and its demand before forwarding retained events.
|
||||
|
||||
False once a device whose credential stopped standing is closed with
|
||||
1008, which sends it to check: otherwise its frames would still be
|
||||
@@ -1722,12 +1722,18 @@ async def flow_events(websocket: WebSocket, ticket: str = "", token: str = "") -
|
||||
device_def = _device_def(websocket.app, device)
|
||||
wanted &= only
|
||||
demand.want(viewer, wanted)
|
||||
return True
|
||||
|
||||
async def catch_up() -> bool:
|
||||
if not await rescope():
|
||||
return False
|
||||
await send_snapshot()
|
||||
return True
|
||||
|
||||
told = await send_snapshot()
|
||||
|
||||
async with event_bus.subscribe() as queue:
|
||||
# Listen before reading state: a value changing while the snapshot is
|
||||
# sent must follow it on the socket, even if it never changes again.
|
||||
told = await send_snapshot()
|
||||
receiver = asyncio.create_task(_receive(websocket))
|
||||
# Where a live view this socket is one end of reaches it. Its own
|
||||
# outbox rather than the bus's queue, which drops when full.
|
||||
@@ -1741,6 +1747,7 @@ async def flow_events(websocket: WebSocket, ticket: str = "", token: str = "") -
|
||||
await websocket.send_text(demand_frame(ports))
|
||||
live_view.sessions.attach(device, endpoint)
|
||||
outbox = asyncio.create_task(endpoint.next())
|
||||
catching_up = False
|
||||
try:
|
||||
while True:
|
||||
sender = asyncio.create_task(queue.get())
|
||||
@@ -1845,10 +1852,13 @@ async def flow_events(websocket: WebSocket, ticket: str = "", token: str = "") -
|
||||
except asyncio.QueueEmpty:
|
||||
break
|
||||
|
||||
# A panel this far behind lost events the bus dropped for it:
|
||||
# its demand, a dashboard published or its own unpairing. It
|
||||
# catches up once this batch is out, as after a dashboard.
|
||||
resync = only is not None and event_bus.dropped(queue)
|
||||
# Every client catches up after overflow. A lost event may be
|
||||
# a value that never changes again, or a device's unpairing.
|
||||
lost = event_bus.dropped(queue)
|
||||
catching_up = catching_up or lost
|
||||
if lost and not await rescope():
|
||||
return
|
||||
resync = False
|
||||
if only is None:
|
||||
fresh = hidden_from(user, websocket.app)
|
||||
if fresh != hidden:
|
||||
@@ -1883,8 +1893,12 @@ async def flow_events(websocket: WebSocket, ticket: str = "", token: str = "") -
|
||||
for frame in media_frames(out, wanted, store):
|
||||
await websocket.send_bytes(frame)
|
||||
await _send(websocket, out)
|
||||
if resync and not await catch_up():
|
||||
return
|
||||
# Send retained events before the recovery snapshot: values
|
||||
# left in the queue would otherwise overwrite its newer state.
|
||||
if resync or (catching_up and queue.empty()):
|
||||
if not await catch_up():
|
||||
return
|
||||
catching_up = catching_up and not queue.empty()
|
||||
except (WebSocketDisconnect, RuntimeError):
|
||||
# A peer that goes away mid-send takes the RuntimeError route
|
||||
# ("websocket.send after websocket.close") rather than the clean
|
||||
|
||||
Reference in New Issue
Block a user