Skip to content

Add force-refresh and per-checker timeout race to HealthCheckManager in src/config/health.ts #370

Description

@Jagadeeshftw

📌 Description

HealthCheckManager in src/config/health.ts caches the last report and checkAll() runs every checker in parallel via Promise.all(). Two gaps: (1) getLastReport() can return a stale report between background intervals, so /health/ready lags real degradation; (2) if a single checker hangs despite its own timeout, Promise.all blocks the whole endpoint. Add an optional forceRefresh and wrap each checker in a Promise.race timeout.

💡 Why it matters: A stale or hung health report can keep an unhealthy instance in rotation.

🧩 Requirements and context

  • Add an optional forceRefresh parameter to recompute checks on demand for readiness.
  • Wrap each checker in Promise.race([check, timeout]) so one hang cannot block the report.
  • Mark a timed-out checker as degraded/unhealthy with a clear reason.
  • Keep the background interval behaviour for liveness.
  • Add tests for stale-vs-fresh and a hung checker.

Non-functional requirements

  • Must be secure, tested, and documented.
  • Should be efficient and easy to review.

🛠️ Suggested execution

1. Fork the repo and create a branch

git checkout -b health-force-refresh-timeout

2. Implement changes

  • Write/modify the relevant source: src/config/health.ts, src/routes/health.ts
  • Write comprehensive tests: tests/health.test.ts, tests/health-ready.test.ts
  • Add documentation: inline TSDoc + README health section
  • Include TSDoc doc comments on checkAll/getLastReport
  • Validate security assumptions: forceRefresh cannot be abused for DoS

3. Test and commit

  • Run tests:
npm test
  • Cover edge cases: stale report, forced refresh, hung checker timeout
  • Include test output and security notes in the PR description.

Example commit message

feat(health): add forceRefresh and per-checker timeout race to HealthCheckManager

✅ Acceptance criteria

  • forceRefresh recomputes checks on demand
  • Each checker is bounded by a Promise.race timeout
  • A hung checker is reported degraded, not blocking
  • Background liveness behaviour preserved
  • Tests cover stale, forced, and hung paths

🔒 Security notes

Gate or rate-limit forceRefresh so an unauthenticated client cannot trigger expensive checks repeatedly (DoS vector).

📋 Guidelines

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

Metadata

Metadata

Assignees

Labels

GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial CampaignGrantFox official campaign issueStellar WaveIssues in the Stellar wave programbackendBackend service workobservabilityLogging / metrics / tracingreliabilityReliability

Type

Fields

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions