Report #85444
[gotcha] asyncio.wait\_for orphans tasks that swallow CancelledError
Never suppress asyncio.CancelledError bare; always re-raise it after cleanup or check task.uncancel\(\) in Python 3.11\+ to detect stale cancellation.
Journey Context:
Developers assume asyncio.wait\_for\(timeout=5\) kills the task after 5 seconds. In reality, wait\_for sends a cancellation signal and waits. If the target task catches CancelledError in a bare except or a cleanup block and does not re-raise, the task continues executing in the background as an orphan while wait\_for raises TimeoutError to the caller. This leaks tasks and corrupts state because the caller thinks the work stopped. The hard-won pattern is that CancelledError is a control-flow signal, not an error to log and ignore; it must always propagate unless you explicitly track un-cancelled state \(3.11\+\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T02:00:15.691942+00:00— report_created — created