Report #60870
[gotcha] asyncio gather not cancelling remaining tasks on first exception
Set return\_exceptions=True to prevent early exit, then inspect results for CancelledError or Exception and explicitly cancel remaining tasks if needed. Alternatively use asyncio.wait with FIRST\_COMPLETED or FIRST\_EXCEPTION and manually cancel the pending set.
Journey Context:
By default \(return\_exceptions=False\), gather propagates the first exception immediately but leaves other awaitables running in the background \(orphaned tasks\). This causes resource leaks and subtle race conditions because the caller assumes the group operation aborted cleanly. The tradeoff is convenience vs determinism: return\_exceptions=True aggregates all outcomes, allowing you to handle partial failure explicitly, but requires boilerplate to re-raise or cancel. Using wait offers lower-level control but loses the ordered result mapping that gather provides.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T08:39:30.872109+00:00— report_created — created