Skip to content

fix(docker-compose.yaml): add mongo healthcheck and fix server startup race condition#313

Open
Anton-dev3306 wants to merge 1 commit into
QuoteVote:mainfrom
Anton-dev3306:fix/docker-healthcheck
Open

fix(docker-compose.yaml): add mongo healthcheck and fix server startup race condition#313
Anton-dev3306 wants to merge 1 commit into
QuoteVote:mainfrom
Anton-dev3306:fix/docker-healthcheck

Conversation

@Anton-dev3306
Copy link
Copy Markdown
Contributor

Description

This PR fixes a race condition between the server and mongo containers on cold starts. The server service was configured with a bare depends_on: mongo, which only waits for the MongoDB container to start — not for MongoDB to be ready to accept connections. This caused the Node.js server to attempt a connection before mongod finished initializing, relying on restart: always to recover silently.

Changes

  • Healthcheck added to mongo: Docker now runs db.adminCommand('ping') every 10 seconds to determine when MongoDB is genuinely ready.
  • depends_on updated on server: Changed from a bare service dependency to condition: service_healthy, so the server only starts after MongoDB passes its healthcheck.
  • mongo-express version bump: Updated from 1.0.0-alpha.4 (unmaintained alpha) to 1.0.2 (current stable).

Verification

  • Ran docker compose down -v && docker compose up --force-recreate and confirmed quotevote-server waits for MongoDB to be healthy before starting.
  • Confirmed MongoDB Connected... log appears only after the healthcheck passes.
  • Confirmed mongo-express UI loads correctly on http://localhost:8081.

Related Issue

Fixes #312

@netlify
Copy link
Copy Markdown

netlify Bot commented May 1, 2026

Deploy Preview for quotevote canceled.

Name Link
🔨 Latest commit 1243982
🔍 Latest deploy log https://app.netlify.com/projects/quotevote/deploys/69f4fb8d9469de0008761d2b

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing healthcheck causes race condition between server and mongo

1 participant