FlaskCeleryDramatiq

Async background tasks silently cancelled on view return

critical
configurationUpdated Mar 24, 2026
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.