Files
routstrd/src
redshift cdfde85595 fix: prevent race condition spawning multiple cocod and routstrd instances
When multiple routstrd processes (or CLI auto-starts) bootstrap simultaneously,
each process found cocod/routstrd unreachable, spawned its own copy, and
contended for the same database socket. The paired ~200ms burst timestamps
in the logs were the symptom.

Fixes applied:

- Add cross-process startup lock (process-lock.ts)
  - Uses atomic mkdir as the lock primitive.
  - Stores PID + UUID token; verifies ownership on release to avoid
    removing a lock taken by a new process after the original crashed.
  - Removes stale locks (unreachable PID or lock older than staleAfterMs).
  - Exports withCrossProcessLock() for simple RAII-style usage.

- Fix cocod startup race (cocod-client.ts)
  - Wrap ensureDaemonRunning() in a socket-derived lock path.
  - Re-ping inside the lock before spawning; if another process just started
    cocod, the current process detects it and connects instead of spawning.
  - Switch from 'cocod daemon' to 'cocod init' for cleaner daemonization.
  - Allow exit code 0 from 'cocod init' (normal daemon exit without error).

- Consolidate routstrd daemon startup (daemon-client.ts)
  - startDaemonProcess() now delegates to startDaemon() from start-daemon.ts,
    sharing the same lock and health-check logic.

- Add cross-process lock to routstrd daemon startup (start-daemon.ts)
  - Performs pre-lock isDaemonHealthy() check to skip lock entirely when
    already running.
  - Performs re-check inside the lock before spawning to avoid duplicate
    daemon processes.
2026-04-30 13:36:16 +05:30
..
2026-03-19 16:25:57 +00:00
2026-02-24 05:55:21 +00:00
2026-03-21 21:26:36 +00:00