Async background tasks silently cancelled on view return
criticalconfigurationUpdated Mar 24, 2026
Technologies:
How to detect:
Background tasks spawned in async Flask views using asyncio.create_task() are automatically cancelled when the view function returns, causing silent task failures and potential data loss.
Recommended action:
Do not use asyncio.create_task() for background processing in Flask async views. Use a proper task queue like Celery or RQ instead. For IO-bound concurrent operations that must complete within the request, use asyncio.gather() or await all tasks before returning.