Description
Cold-start schema creation often takes longer than the current 1.5s exponential backoff window, causing secondary PM2 workers to exhaust their retries and crash with "Lock file is already being held" errors.
Current config:
DB_INIT_MAX_ATTEMPTS = 6
DB_INIT_INITIAL_BACKOFF_MS = 50
DB_INIT_MAX_BACKOFF_MS = 1000
Total window: ~1.5 seconds.
Tasks
- Increase Retry Window:
- Update
DB_INIT_MAX_ATTEMPTS to 15 or increase the backoff multipliers to ensure the total wait time is at least 20 seconds.
- Robust Locking:
- Consider updating the
proper-lockfile call to use its internal retries option if it simplifies the code, or simply extend the existing exponential backoff logic.
- Update Tests:
- Add/update unit tests to verify the extended retry logic.
PO Refinement (Round 1)
Acceptance Criteria
Scope Boundary
- IN SCOPE: Updating constants and retry logic in
apps/webhook-listener/src/db/schema.ts.
- OUT OF SCOPE: Changing the locking strategy (e.g., no Redis or DB-based locks).
- OUT OF SCOPE: Modifying
ecosystem.config.js or PM2 settings.
Nx Projects Affected
webhook-listener (strictly code/test changes in src/db/).
Dependencies
Effort Estimate
- XS (Extra Small). Surgical constant update.
Validation Strategy
- Unit Tests: Mock
proper-lockfile to simulate a held lock and assert retry count.
- Manual: Deploy to Mac Mini and perform
pm2 restart webhook-listener to verify clean cluster boot.
Description
Cold-start schema creation often takes longer than the current 1.5s exponential backoff window, causing secondary PM2 workers to exhaust their retries and crash with "Lock file is already being held" errors.
Current config:
DB_INIT_MAX_ATTEMPTS = 6DB_INIT_INITIAL_BACKOFF_MS = 50DB_INIT_MAX_BACKOFF_MS = 1000Total window: ~1.5 seconds.
Tasks
DB_INIT_MAX_ATTEMPTSto 15 or increase the backoff multipliers to ensure the total wait time is at least 20 seconds.proper-lockfilecall to use its internalretriesoption if it simplifies the code, or simply extend the existing exponential backoff logic.PO Refinement (Round 1)
Acceptance Criteria
Scope Boundary
apps/webhook-listener/src/db/schema.ts.ecosystem.config.jsor PM2 settings.Nx Projects Affected
webhook-listener(strictly code/test changes insrc/db/).Dependencies
Effort Estimate
Validation Strategy
proper-lockfileto simulate a held lock and assert retry count.pm2 restart webhook-listenerto verify clean cluster boot.