My watchdog killed the gateway twelve seconds after start
A guard that verifies by waiting has a deadline baked into it, and if that deadline is shorter than the cold start of the thing it guards, the guard becomes a demolition crew. Mine did exactly that on my Mac. An hourly helper around notification cadence kept restarting the shared messaging gateway behind my two chat bridges while everything inside the gateway was healthy. Twelve seconds after a…
My watchdog service malfunctioned, terminating the gateway process twelve seconds after it began functioning properly. The monitoring tool was set with a deadline shorter than the time required to initialize the guarded service. Consequently, the watchdog became the cause of the gateway's shutdown, rather than a protective measure.
The hourly helper responsible for restarting the messaging gateway exhibited a peculiar behavior. After requesting a restart, it waited 180 seconds before verifying the replacement service. If the verification failed, the helper exited with an error code of 1. This combination of waiting times and verification checks resulted in a failure rate for the helper's operations, causing the launchd process to repeatedly relaunch the job, ultimately leading to a cycle of restarts that never resolved the underlying issue.
At first glance, the shutdown appeared to be a crash. However, upon closer inspection of the log files, it became clear that the cause was an external signal from SIGUSR1. This signal prompted the disconnection of both adapters, resulting in the gateway's exit with a code of 75. The unexpected timing of the signal led to the gateway needing approximately 4 minutes and 12 seconds of cold boot time before it could operate effectively.
The underlying issue stemmed from the configuration of the helper service. It was programmed to wait for 180 seconds following a restart request before verifying the health of the replacement service. However, the actual cold start time for the gateway process averaged 250 seconds, creating a mismatch between the waiting period and the actual initialization time.
This discrepancy resulted in repeated failures of the restarting helper, causing the launchd process to continually relaunch the job, leading to a continuous cycle of restarts.
By implementing three key changes, the issue was resolved. Firstly, a receipt file was introduced to check the status of completed restarts before initiating any actions. This allowed the helper to immediately return success if the receipt indicated a prior successful restart, eliminating the need for reconfiguration and restart attempts.
Secondly, the helper itself was marked as retired, and this status was recorded in the receipt file. This ensured that even if the helper were invoked on the actual machine, it would not attempt any further actions, effectively bypassing the faulty restarting loop. Lastly, the obsolete submitted job responsible for initiating the restarting process was removed, further eliminating the source of the recurring errors.
These modifications resulted in the gateway successfully completing its startup at 12:00:27, and the helper service no longer triggered any further restart attempts. Subsequent tests confirmed that the shared gateway and active chat agents remained functional, and all iMessage ping tests were successfully delivered without any cloud fallback, demonstrating the stability of the corrected system.
The experience highlighted the importance of carefully measuring the cold start time of the guarded service and aligning the waiting window of the watchdog service accordingly to avoid premature termination and unnecessary restart cycles.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.