Report #51777
[gotcha] Asyncio task cancelled during critical cleanup loses data
Wrap critical sections in asyncio.shield\(\) to prevent cancellation during commit or flush operations
Journey Context:
When cancel\(\) is called, the event loop injects CancelledError at the next await point. If this occurs during a database commit or file write, partial data persists causing corruption. Shield creates a protective inner task that continues even if the parent is cancelled. Only use for true critical sections, as it delays response to legitimate cancellation requests.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T17:24:05.530084+00:00— report_created — created