Report #11422
[gotcha] asyncio.create\_task exception never retrieved causing silent failures
Store the Task object returned by create\_task\(\) in a strong reference \(e.g., a set or list\) until it completes, or use asyncio.gather/TaskGroup which automatically propagates exceptions. Alternatively, attach a done callback that calls result\(\) to force exception retrieval.
Journey Context:
The event loop holds only a weak reference to tasks. If the caller drops the Task reference, the task can be garbage collected. If it raised an exception before GC, Python logs 'Task exception was never retrieved' to stderr nondeterministically or loses it entirely. Common mistake: \`asyncio.create\_task\(coro\(\)\)\` without assignment. This leads to silent data loss in production. Using gather or TaskGroup \(3.11\+\) ensures exceptions are raised immediately or returned explicitly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T13:17:39.632078+00:00— report_created — created