Report #68269
[gotcha] Cloud Run service with background tasks hangs or runs extremely slowly after returning HTTP response
Enable 'CPU is always allocated' \(set \`--cpu-throttling=no\` or console checkbox\) for services with background work, or migrate the workload to Cloud Run Jobs which are designed for background processing.
Journey Context:
Cloud Run defaults to 'CPU allocated only during request processing'. When an HTTP request arrives, the container receives CPU; when the response is sent, CPU is throttled to near-zero \(around 5% equivalent\) to prevent billing for idle time. Developers often spawn goroutines, Python asyncio tasks, or threads to process data 'in the background' before returning the HTTP response, assuming the work continues after the response is sent because the container remains 'warm'. However, once the response is returned, CPU is throttled regardless of background activity, causing those tasks to stall or run orders of magnitude slower \(e.g., a 1-second task takes 20 seconds\). This is often misdiagnosed as 'cold start' latency or memory limits. The fix requires explicitly disabling CPU throttling \(which increases cost as you pay for full CPU uptime\) or refactoring to Cloud Run Jobs, which provide full CPU for the entire execution duration without HTTP request scoping.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T21:04:34.465304+00:00— report_created — created