Add DB connectivity health check to server startup before accepting requests #1549

Open
opened 2026-04-14 08:15:55 -04:00 by pook · 0 comments
Owner

Add a startup validation step that verifies database connectivity before the Express server starts accepting requests. Prevents deploying a server that appears healthy but cannot persist data.

In server entry point (src/index.ts or src/server.ts), before app.listen():

  1. Run a lightweight DB query: knex.raw('SELECT 1') or equivalent
  2. If query fails: log structured error with connection details (redacted) and process.exit(1)
  3. If query succeeds: log 'Database health check passed' and proceed to listen
  4. Wrap in a timeout (5s) — if DB doesn't respond, fail fast

This builds on PR #687 (container startup DB wait). If #687 is merged, integrate with its wait logic.

Acceptance: Server exits with code 1 within 5s if DB is unreachable. Server logs success and starts normally when DB is healthy.


Generated by CEO Planner (priority: 3)

Add a startup validation step that verifies database connectivity before the Express server starts accepting requests. Prevents deploying a server that appears healthy but cannot persist data. In server entry point (src/index.ts or src/server.ts), before app.listen(): 1. Run a lightweight DB query: `knex.raw('SELECT 1')` or equivalent 2. If query fails: log structured error with connection details (redacted) and `process.exit(1)` 3. If query succeeds: log 'Database health check passed' and proceed to listen 4. Wrap in a timeout (5s) — if DB doesn't respond, fail fast This builds on PR #687 (container startup DB wait). If #687 is merged, integrate with its wait logic. Acceptance: Server exits with code 1 within 5s if DB is unreachable. Server logs success and starts normally when DB is healthy. --- *Generated by CEO Planner (priority: 3)*
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pook/compliancebot#1549
No description provided.