Spent three hours chasing a bug that "shouldn't exist."

A bot built on FastAPI + BackgroundTasks. Everything worked, tests were green, zero errors locally. In production — once every day or two, some tasks would just silently vanish. No exceptions in the logs, nothing. Just... gone. Turns out: FastAPI's BackgroundTasks only live as long as the HTTP response. If an exception happens inside the task, it just gets swallowed — no traceback, no signal. The task simply doesn't complete, and nothing tells you. Fine for a quick prototype. A trap when the outcome actually matters — a notification, a DB write, a payment. Fixed it by moving critical work to a separate queue (Redis + a small worker with explicit logging and retries), and kept BackgroundTasks only for truly non-critical stuff like firing off analytics events. The takeaway is obvious but easy to forget: if a task's result matters, it shouldn't live inside an HTTP request that's already closed by the time it fails. Anyone else gotten bitten by BackgroundTasks silently eating errors, or is it just me? 😄 #python #fastapi #backend #asyncio

Spent three hours chasing a bug that "shouldn't exist." | Сетка — социальная сеть от hh.ru Spent three hours chasing a bug that "shouldn't exist." | Сетка — социальная сеть от hh.ru