Skip to content
Latchkey

Firebase "Container Healthcheck failed" (gen2 functions) in CI

Second-generation functions run on Cloud Run. After deploy, the platform starts the container and waits for it to listen. A crash on startup or a slow init makes the healthcheck fail, and the deploy is rolled back.

What this error means

A gen2 functions deploy fails with "Error: Container Healthcheck failed. The user-provided container failed to start and listen on the port defined provided by the PORT environment variable."

firebase
Error: Container Healthcheck failed. The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable.

Common causes

The function throws during cold start

Top-level code that reads missing config or a bad import crashes the container before it can listen.

Initialization exceeds the startup window

Slow module load or a blocking network call at import time can push past the healthcheck timeout.

How to fix it

Move heavy work out of module load

  1. Read config and open connections inside the handler, not at import time.
  2. Check Cloud Run logs for the startup crash the healthcheck reports.
  3. Redeploy once the container starts cleanly.
Terminal
firebase deploy --only functions:api --project my-project --debug

Set required env before startup

Provide the runtime config the function reads so cold start does not throw, using functions params or environment configuration.

How to prevent it

  • Keep module-load work minimal so cold start is fast and safe.
  • Set all required runtime configuration before deploy.
  • Check Cloud Run startup logs when a healthcheck fails.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →