From e18c3a7bb291b32a9acf3c2307ad2e3d3b5b9094 Mon Sep 17 00:00:00 2001 From: Anthony Ettinger Date: Mon, 30 Nov 2026 20:30:05 +0000 Subject: [PATCH] fix(dev2/c0mpute-gateway): startup grace in the watchdog, no restart loop Since c0mpute 0.3.136 the worker brings its apps up before it opens :7777; on 2026-11-30 that took 3.5 min. The watchdog restarted any worker whose /healthz failed for 12 s, so from 20:13 to 20:29 UTC it restarted the worker every 2 min and :7777 never came up: every Moshpit name on c0mpute (my.ip, mums.flower, dbml.db, autoinfluencer) answered 502/503. Now a worker that became active less than C0MPUTE_GATEWAY_GRACE (480 s) ago is left to finish starting. Installed on dev2 (backup /usr/local/sbin/c0mpute-gateway-watchdog.bak-20261130-grace). Co-Authored-By: Claude Opus 5.5 --- dev2/c0mpute-gateway/c0mpute-gateway-watchdog | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/dev2/c0mpute-gateway/c0mpute-gateway-watchdog b/dev2/c0mpute-gateway/c0mpute-gateway-watchdog index 7ab52f4..056b6f6 100755 --- a/dev2/c0mpute-gateway/c0mpute-gateway-watchdog +++ b/dev2/c0mpute-gateway/c0mpute-gateway-watchdog @@ -22,6 +22,20 @@ for wait in 0 1 1 2 3 5; do ok && exit 0 done +# A worker that started recently is still coming up: since 0.3.136 it brings its +# apps up before it opens :7777, which took 3.5 min on 2026-11-30. Restarting it +# inside that window only starts the wait again (it looped every 2 min for 15 min +# and took every Moshpit name on c0mpute down). Leave it alone for GRACE seconds. +GRACE="${C0MPUTE_GATEWAY_GRACE:-480}" +if systemctl is-active --quiet "$UNIT"; then + since=$(systemctl show -p ActiveEnterTimestampMonotonic --value "$UNIT" 2>/dev/null || echo 0) + now=$(awk '{printf "%d", $1 * 1000000}' /proc/uptime) + if [ "${since:-0}" -gt 0 ] && [ $(( (now - since) / 1000000 )) -lt "$GRACE" ]; then + log "$URL not answering yet, but $UNIT started $(( (now - since) / 1000000 )) s ago (grace ${GRACE} s); waiting" + exit 0 + fi +fi + # Someone may be running a worker by hand on :7777 (a session relaunch). It is not # answering either, so the unit is the one to bring back. if systemctl is-active --quiet "$UNIT"; then