Report #4154
[gotcha] asyncio.gather not cancelling remaining tasks when one raises exception
Use 'asyncio.wait\(return\_when=asyncio.FIRST\_EXCEPTION\)' and manually cancel the remaining tasks, or set 'return\_exceptions=True' in gather and handle exceptions explicitly, instead of relying on gather for atomic cancellation.
Journey Context:
By default, gather\(return\_exceptions=False\) propagates the first exception immediately to the caller, but does NOT cancel the other awaitables. They continue running in the background, potentially causing side effects or resource leaks. Developers often assume gather is transactional \(all-or-nothing\), but it lacks atomic cancellation. This leads to zombie tasks after partial failure in distributed async workflows where cleanup is critical.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T18:54:27.760345+00:00— report_created — created