#22108: fix: prevent local DoS by fully clearing systemd services on uninstall
gateway
size: XS
Cluster:
Gateway and System Fixes
Hello OpenClaw Team,
This PR fixes a critical bug in the uninstallation process that causes a Local Denial of Service (resource exhaustion) on Linux machines.
**The Issue:**
Currently, both `uninstallSystemdService` and `uninstallLegacySystemdUnits` remove the physical unit files and run `disable --now`. However, they fail to run `systemctl daemon-reload` and `systemctl reset-failed`. As a result, `systemd` keeps the ghost units in memory and enters an infinite crash/restart loop.
**The Impact:**
1. This crash loop continuously writes logs to the Linux `pstore`, which mounts directly to the motherboard's NVRAM. Within weeks, this fills up the entire NVRAM (8-16MB on average), forcing the BIOS into a locked "Write Protected" state to prevent hardware damage.
2. During system shutdown, the looping ghost service prevents `systemd` from unmounting `/var/cache`. The kernel aborts the power-off and forces an unkillable reboot loop. I documented this entire crisis and the community response here: https://www.reddit.com/r/openclaw/comments/1r98r6x/bug_report_leftover_openclawgatewayservice_acts/
**The Fix:**
I updated both uninstallation functions to include:
- `systemctl daemon-reload` to flush the removed unit from systemd's memory.
- `systemctl reset-failed` to stop any existing crash loops.
This ensures the system is left in a clean state and prevents hardware-level locking.
Thanks,
Berke Serçe
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds `systemctl daemon-reload` and `systemctl reset-failed` calls to both `uninstallSystemdService` and `uninstallLegacySystemdUnits` functions. These commands flush removed systemd units from memory and clear any crash loops, preventing a Local DoS condition where ghost services continuously crash and fill NVRAM with logs.
**Major changes:**
- Added `daemon-reload` after unit file removal in both uninstall functions to ensure systemd picks up the removed unit
- Added `reset-failed` to stop any existing crash/restart loops
- In `uninstallLegacySystemdUnits`, both calls are wrapped in the existing `systemctlAvailable` check
**Issues found:**
- The new `daemon-reload` and `reset-failed` calls don't check exit codes, unlike the same calls in `installSystemdService` (lines 207-209). If these commands fail silently, users won't know the cleanup didn't complete, potentially leaving the DoS condition unresolved.
<h3>Confidence Score: 3/5</h3>
- This PR is mostly safe to merge but has missing error handling
- The fix addresses a critical bug and the approach is sound - adding `daemon-reload` and `reset-failed` is the correct solution to prevent systemd ghost units. However, the implementation lacks error checking on these critical cleanup operations. In `installSystemdService`, the same `daemon-reload` call checks exit codes and throws errors (lines 207-209), but the uninstall functions don't. This inconsistency could leave users unaware if cleanup fails. Since uninstall is a cleanup operation (not critical path), warnings would be more appropriate than exceptions.
- Pay attention to `src/daemon/systemd.ts` - ensure error handling is added for the new systemctl calls
<sub>Last reviewed commit: 2e2f82f</sub>
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#16016: fix: update systemd unit version on gateway restart
by jbold · 2026-02-14
80.7%
#21212: fix: detect and manage systemd system services (rebased)
by growthringsadvisory · 2026-02-19
80.4%
#16185: fix: patch systemd unit version before service restart
by nozh · 2026-02-14
79.2%
#9214: Fix: EPIPE exception in systemd service operations
by vishaltandale00 · 2026-02-05
74.8%
#21188: doctor: clean up legacy Linux gateway services
by Phineas1500 · 2026-02-19
74.8%
#13084: fix(daemon): multi-layer defense against zombie gateway processes
by openperf · 2026-02-10
74.8%
#18498: daemon: load systemd EnvironmentFile and drop-ins so gateway status...
by saurav470 · 2026-02-16
74.4%
#23666: fix(doctor): openclaw-browser.service falsely flagged as duplicate ...
by yinghaosang · 2026-02-22
74.1%
#21591: fix(update): prevent double restart when refreshing service env
by irchelper · 2026-02-20
73.9%
#9036: fix: add systemd restart limits to prevent infinite crash-loops
by joetomasone · 2026-02-04
73.4%