Skip to content
This repository was archived by the owner on Jun 19, 2026. It is now read-only.

fix: Docker healthcheck cascade — service_started → service_healthy#174

Open
GoThundercats wants to merge 2 commits into
rohitdash08:mainfrom
GoThundercats:fix-docker-health-cascade
Open

fix: Docker healthcheck cascade — service_started → service_healthy#174
GoThundercats wants to merge 2 commits into
rohitdash08:mainfrom
GoThundercats:fix-docker-health-cascade

Conversation

@GoThundercats

Copy link
Copy Markdown

Summary

Fixes the cold-start 502 race condition identified during a Docker audit.
Only postgres had a healthcheck; redis, backend, and nginx were
all using service_started, meaning containers started before dependencies
were actually ready to serve traffic.

Problems Fixed

Service Was Fix
redis No healthcheck Added redis-cli ping healthcheck
backend Depended on redis via service_started Now service_healthy + own healthcheck added
nginx Depended on backend via shorthand [backend] Now condition: service_healthy
packages/backend/Dockerfile No HEALTHCHECK instruction Added HEALTHCHECK pointing at /health
app/Dockerfile No HEALTHCHECK instruction Added HEALTHCHECK via wget (Alpine-compatible)

Changes

  • docker-compose.yml — redis healthcheck block; backend healthcheck block with start_period: 30s (covers flask init-db time); nginx depends_on upgraded to condition: service_healthy; nginx healthcheck via /nginx_status
  • packages/backend/Dockerfile — added curl to apt deps; added HEALTHCHECK instruction
  • app/Dockerfile — added HEALTHCHECK via wget --spider (BusyBox-compatible)

Health Chain After Fix

postgres (healthy) → redis (healthy) → backend (healthy) → nginx (starts)

The /health endpoint (GET → {"status": "ok"}) already exists in
packages/backend/app/__init__.py — no application code changes needed.

Testing

docker compose up --build
docker compose ps   # all services should reach 'healthy' state

Problems fixed:
- redis: add healthcheck (redis-cli ping) so backend can depend on service_healthy
- backend: add healthcheck (/health endpoint) + start_period=30s for init-db
- backend Dockerfile: add HEALTHCHECK instruction + curl to apt deps
- nginx: upgrade depends_on backend to service_healthy; add healthcheck
- app/Dockerfile: add HEALTHCHECK via wget (nginx:alpine compatible)

All service_started conditions upgraded to service_healthy via audit.
The /health endpoint already existed in app/__init__.py.
@GoThundercats

Copy link
Copy Markdown
Author

Updated the PR to include a comprehensive healthcheck audit. Beyond the initial backend/nginx race condition, I've also added health-aware dependencies for the redis-exporter and frontend-dev services to ensure the monitoring stack and dev-server boot reliably.

@GoThundercats

Copy link
Copy Markdown
Author

👋 Just following up — happy to address any feedback or make adjustments if this needs changes before review. Let me know!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant