Report #15950
[gotcha] Asyncio shielded task continues after parent cancellation but parent CancelledError is suppressed or lost
Always re-raise CancelledError after awaiting a shielded task if the shield was used to protect cleanup; structure code as \`try: await shielded\_task except CancelledError: shielded\_task.cancel\(\); await shielded\_task; raise\` to ensure propagation.
Journey Context:
Developers use \`asyncio.shield\(\)\` to prevent a long-running operation from being aborted by a timeout or cancellation. However, when the parent task receives a CancelledError, it often catches it to perform cleanup, but the shielded task is now orphaned. If the parent suppresses the CancelledError \(e.g., via a bare \`except\` or logging and swallowing\), the event loop doesn't know the parent was cancelled. The fix requires explicitly re-raising CancelledError after ensuring shielded children are either awaited to completion or cancelled themselves; this maintains the cancellation chain required by asyncio's cooperative multitasking model.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T01:24:32.296081+00:00— report_created — created