Report #41389
[gotcha] GCP Cloud Run throttles CPU to zero immediately after HTTP response causing async work and log flushes to fail silently
Enable 'CPU always allocated' in Cloud Run service settings \(billing changes to per-instance rather than per-request\) OR ensure all async work \(logging, Pub/Sub publishes, database commits\) is fully awaited and completed before returning the HTTP response; do not fire-and-forget background tasks in Cloud Run without CPU always allocated.
Journey Context:
Cloud Run's default 'CPU only allocated during request processing' model is a serverless optimization where instances are frozen after the HTTP response is sent. Users expect a 'main\(\)' function semantics where code after the response return continues briefly, but Cloud Run sends SIGTERM or simply freezes the container. This causes fire-and-forget logging \(like stdout flush\) or async Pub/Sub publishes to be silently dropped, leading to 'success' HTTP logs but missing downstream data. The 'CPU always allocated' setting switches to traditional VM-like billing where the instance stays warm and responsive, but costs accrue for idle time.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T23:56:42.229287+00:00— report_created — created