Skip to content

Add connection retry with exponential backoff on startup in src/db/index.ts #169

Description

@Jagadeeshftw

📌 Description

src/db/index.ts establishes the Postgres pool at startup; if the DB isn't reachable yet (e.g. during a coordinated deploy where the DB container is still starting), the service likely fails hard instead of retrying.

🧩 Requirements and context

  • Retry the initial connectivity check with exponential backoff up to a configurable max attempts/time.
  • Log each retry attempt at a reasonable level (warn, not error, until attempts are exhausted).
  • Fail fast with a clear error once retries are exhausted.

🛠️ Suggested execution

  1. Wrap the startup connectivity check in src/db/index.ts with a retry/backoff loop.
  2. Make max attempts and base delay configurable via src/config.ts.
  3. Add tests simulating transient connection failure followed by success, and exhausted-retries failure.

✅ Acceptance criteria

  • A transient startup failure followed by DB availability results in successful startup (no manual restart needed).
  • Persistent unavailability fails startup with a clear, actionable error after the configured attempts.

🔒 Security notes

Backoff must be bounded (max attempts/time) so a permanently-unreachable DB doesn't retry forever and mask an outage.

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions