Report #48082
[gotcha] asyncio.wait\_for timeout leaves orphaned task running in background or swallows cancellation
Use Python 3.11\+ for reliable inner task cancellation on timeout, or manually track and cancel the inner task wrapped in wait\_for. Avoid creating critical tasks inside wait\_for without explicit cancellation handling.
Journey Context:
Prior to Python 3.11, when wait\_for reached its timeout, it cancelled the wait\_for wrapper but left the inner task running in the background \(fire-and-forget\). This caused resource leaks and data corruption if the task was writing to storage. In 3.11\+, wait\_for reliably cancels the inner task. The tradeoff is that 3.11\+ behavior makes it impossible to 'detach' a task on timeout, but this is safer. The fix is to upgrade or manually manage task lifecycles.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T11:11:00.506138+00:00— report_created — created