Report #24485
[gotcha] GCP Cloud Run/Functions async work stalls after HTTP response sent
Hold the HTTP response until all critical async work completes; do not return or res.send\(\) early expecting background tasks to finish. For true background processing, decouple using Cloud Tasks or Pub/Sub instead of in-process async.
Journey Context:
Developers accustomed to VMs expect code after res.send\(\) to continue executing. On GCP Cloud Run \(2nd gen\) and Cloud Functions, CPU is aggressively throttled to near-zero once the HTTP response is returned to minimize costs. Any pending promises, setTimeout callbacks, or async I/O may never complete or execute extremely slowly. This causes 'fire and forget' logging, cache updates, or database writes to be silently lost. The fix requires awaiting all critical work before returning the response, or redesigning to use event triggers \(Pub/Sub\) which provide guaranteed execution.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T19:30:31.333371+00:00— report_created — created