Cloud Run's CPU throttling silently freezes background tasks after HTTP response
A developer building an agent on Google Cloud Run discovered that background tasks scheduled after sending an HTTP response were silently freezing for minutes or never completing. The root cause is Cloud Run's default request-based CPU allocation, which throttles CPU to near zero as soon as a response is sent and only restores it when the next request arrives. Because the background task neither failed nor logged errors, the bug was difficult to detect — frozen mid-network-call, it would only resume when unrelated traffic hit the same instance. The issue affects any post-response work pattern, including FastAPI's BackgroundTasks, bare asyncio.create_task calls, or in-process dispatch queues. The fix is to complete all critical work before sending the response, or to offload tasks to an external service that runs independently of the request lifecycle.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in