Warning
Here be dragons! This plugin really only works in Garry's Mod sanely. Untested elsewhere.
serverplugin_guarddog is a Source server plugin that detects frozen server execution and triggers a kill sequence when SRCDS stops responding.
Features:
- Monitors
GameFrameprogress from the Source server - Starts a timeout countdown when frames are missing
- Sends
SIGUSR1andSIGUSR2after configurable delays - Forces a process kill if the hang persists
- Optional Linux helper support via
dog_frozenshell script
You need gmsv_segfault to utilize this watchdog properly.
guarddogwatches for server freezes and generates failure signalsgmsv_segfaultis a companion crash-handling module that catches signals likeSIGUSR1/SIGUSR2and writes diagnostics or backtraces- Used together,
guarddogcan detect hangs andgmsv_segfaultcan capture useful crash/debug output before the process exits and recover from some infinite loops in Lua.
When gmsv_segfault receives SIGUSR1, it does not immediately crash the server. Instead, it installs a short Lua hook on the main Lua state and forces a Lua error after a small number of bytecode instructions.
This means that if the server is stuck in a Lua infinite loop, gmsv_segfault can break out of the loop by injecting a lua_error through the hook. With guarddog configured to send SIGUSR1 before the final kill timeout, the pair can recover from programming loops and still preserve a signal dump for debugging.
gmsv_segfault treats SIGUSR1 as a non-fatal recovery signal. When it receives SIGUSR1, it installs the Lua hook and then returns from the signal handler instead of immediately dumping and exiting.
guarddog detects recovery when the server resumes normal frame progress: GameFrame is executed again, which sets has_fuzzy_respose true and clears the timeout state.
The practical sign of recovery is:
- the log shows
SIGUSR1:lua_sethook_hack GameFrameruns again andguarddoglogs a recovery marker likeR>- no fatal crash dump is produced for that signal
- the process continues running after the injected Lua error
If the server does not recover, guarddog will still continue its hang timeout and eventually force the final kill sequence.
- Install premake
- Run
premake5from the repo root to generate a build project for your platform - Build the generated solution or makefiles
- Produced artifact:
serverplugin_guarddog.dllon Windowsserverplugin_guarddog.soon Linux
- Copy the built
serverplugin_guarddog.dll/serverplugin_guarddog.sointogarrysmod/addons/along with the VDF - Ensure SRCDS loads the plugin via the normal server plugin mechanism (plugin_X)
- Optionally install
gmsv_segfaultalongside this plugin to capture signal dumps forSIGUSR1/SIGUSR2
The following environment variables are supported:
DOG_DELAY— maximum hang timeout in seconds before the plugin kills the server (default:22)DOG_USR1DELAY— delay in seconds before sendingSIGUSR1DOG_USR2DELAY— delay in seconds before sendingSIGUSR2DOG_SHELL=1— enabledog_frozenhelper behavior on Linux
- The plugin description returned by the module is
Server Freeze Guard - On Linux,
DOG_SHELL=1causes the plugin to invoke the bundleddog_frozenhelper when crashing guarddogitself does not generate crash dumps; it is primarily a freeze detector and crash trigger
Garry, Metastruct, and everyone who contributed to the Source server crash/debug tooling.