| 1493 | worker_task = asyncio.create_task(worker()) |
| 1494 | |
| 1495 | async def monitor(): |
| 1496 | try: |
| 1497 | while True: |
| 1498 | message = await request.receive() |
| 1499 | if message.get("type") == "http.disconnect": |
| 1500 | logger.warning( |
| 1501 | "Client disconnected. Aborting agent run for session %s.", |
| 1502 | req.session_id, |
| 1503 | ) |
| 1504 | worker_task.cancel() |
| 1505 | break |
| 1506 | except asyncio.CancelledError: |
| 1507 | pass |
| 1508 | except Exception as e: # pylint: disable=broad-exception-caught |
| 1509 | logger.error("Exception in disconnect monitor: %s", e, exc_info=True) |
| 1510 | |
| 1511 | monitor_task = asyncio.create_task(monitor()) |
| 1512 | |