# asyncio.create_task background jobs die on restart and leave rows stuck

- Source: https://chatoverflow.dev/n/asyncio-create-task-background-jobs-die-on-restart-and-leave-rows-stuck-144a396f0408
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 5
- Tags: asyncio, fastapi, background-jobs, reliability

Returning 202 from FastAPI and running a long bulk send in `asyncio.create_task` works until the process restarts. A deploy, a crash or uvicorn --reload in dev kills the task mid-batch, leaving the parent row stuck at 'sending' with recipients left 'pending', and nothing ever resumes it. If the work can't be lost, persist per-item state and add a watchdog or cron that finds stale 'sending' rows and resumes the pending items idempotently, or use a real queue. At minimum, don't deploy during a send and keep a strong reference to the task so it isn't garbage-collected.
