Fix false array-start failure for start_webhook_listener.sh
No 'already running' guard existed — a relaunch (array stop/start that doesn't kill the old node process) would exec straight into node, hit EADDRINUSE on the port, and exit 1 within ~1s. array_started.sh correctly reported that as a failure, even though the prior listener instance was still healthy and serving webhooks the whole time. Confirmed live: the node process from 2026-06-23 (PID 25977) is still running today, and the 2026-07-03 array start logged this exact false failure. Added acquire_lock "continuous" before the exec — an existing, documented common.sh mode (skip gracefully if a healthy instance is running) that wasn't actually used anywhere in the codebase yet.
This commit is contained in:
@@ -27,8 +27,9 @@
|
||||
# ==============================================================================================
|
||||
#
|
||||
# 1. Check WEBHOOK_PORT — exit cleanly if 0 (listener disabled)
|
||||
# 2. Check WEBHOOK_SECRET — generate and persist one if empty
|
||||
# 3. exec node webhook_listener.js — replaces this process; PID stays the same
|
||||
# 2. acquire_lock "continuous" — exit cleanly if a healthy instance is already running
|
||||
# 3. Check WEBHOOK_SECRET — generate and persist one if empty
|
||||
# 4. exec node webhook_listener.js — replaces this process; PID stays the same
|
||||
#
|
||||
# exec is intentional: array_started.sh tracks the PID of this script to check
|
||||
# whether the listener is running. exec preserves that PID across the hand-off
|
||||
@@ -53,11 +54,22 @@
|
||||
# PID of this script to check liveness — exec ensures that PID continues to
|
||||
# refer to the running node process after the hand-off.
|
||||
#
|
||||
# Continuous-Mode Lock, Not Just PID Tracking
|
||||
# array_started.sh only checks whether ITS launch attempt is still alive after
|
||||
# 1s — it has no idea a previous instance might already be listening (e.g. an
|
||||
# array stop/start that didn't kill the old node process). Without its own
|
||||
# guard, a relaunch would exec straight into node, hit EADDRINUSE on the port,
|
||||
# exit 1 almost immediately, and array_started.sh would log a false failure
|
||||
# for a listener that was actually still healthy. acquire_lock "continuous"
|
||||
# detects the live instance and exits 0 instead.
|
||||
#
|
||||
# ==============================================================================================
|
||||
# OPERATIONAL SAFEGUARDS
|
||||
# ==============================================================================================
|
||||
#
|
||||
# WEBHOOK_PORT=0 gate — exits cleanly before any setup if the listener is disabled
|
||||
# acquire_lock "continuous" — exits 0 cleanly if a healthy instance is already running,
|
||||
# instead of relaunching into a port conflict
|
||||
# Secret auto-generate — WEBHOOK_SECRET generated via openssl rand if empty;
|
||||
# persisted to master.conf immediately so restarts reuse it
|
||||
# Shared secret gate — webhook URL must include ?key=<WEBHOOK_SECRET>;
|
||||
@@ -97,6 +109,11 @@ source "$ECOSYSTEM_ROOT/load_config.sh"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Skip gracefully if a healthy instance is already listening — otherwise a
|
||||
# restart that doesn't kill the old node process (array stop/start without a
|
||||
# full reboot) hits EADDRINUSE and array_started.sh logs a false failure.
|
||||
acquire_lock "continuous"
|
||||
|
||||
# ── Auto-generate secret if not yet set ─────────────────────────────────────
|
||||
if [[ -z "${WEBHOOK_SECRET:-}" ]]; then
|
||||
GENERATED=$(openssl rand -hex 32)
|
||||
|
||||
Reference in New Issue
Block a user