Description
When openclash restart is called multiple times, orphaned clash core processes (PPID=1) accumulate in memory. Each orphan consumes ~1.5 GB RSS. On a router with 3.8 GB RAM, 2-3 restarts can trigger OOM.
Root Cause
In /etc/init.d/openclash stop_service(), the fallback cleanup is guarded by procd_running:
procd_kill "openclash"
for i in $(seq 1 10); do
procd_running "openclash" >/dev/null && sleep 1 || break
done
if procd_running "openclash" >/dev/null; then
kill -9 $(pidof clash) 2>/dev/null || true
fi
After procd_kill succeeds, procd_running returns false → the if block is skipped → orphan processes survive. Meanwhile pidof clash still finds them (PPID=1, not managed by procd), but no one kills them.
Steps to Reproduce
- Start OpenClash normally
- Run
/etc/init.d/openclash restart 3 times in succession
- Check process count:
ps | grep clash | wc -l — multiple clash processes accumulate
Impact
- Memory leak: each orphan consumes ~1.5 GB RSS
- On a 3.8 GB router, 3 restarts can exhaust memory
- Orphans are invisible to procd, so normal stop/restart cannot clean them
Environment
- Device: OpenWrt router (3.8 GB RAM)
- OpenClash: v0.47.099
- Mihomo: alpha-g24b6de7
Fix
See PR #5206 — removes the procd_running guard and uses unify_ps_pids "$CLASH" for path-scoped cleanup.
Description
When
openclash restartis called multiple times, orphanedclashcore processes (PPID=1) accumulate in memory. Each orphan consumes ~1.5 GB RSS. On a router with 3.8 GB RAM, 2-3 restarts can trigger OOM.Root Cause
In
/etc/init.d/openclashstop_service(), the fallback cleanup is guarded byprocd_running:After
procd_killsucceeds,procd_runningreturns false → theifblock is skipped → orphan processes survive. Meanwhilepidof clashstill finds them (PPID=1, not managed by procd), but no one kills them.Steps to Reproduce
/etc/init.d/openclash restart3 times in successionps | grep clash | wc -l— multiple clash processes accumulateImpact
Environment
Fix
See PR #5206 — removes the
procd_runningguard and usesunify_ps_pids "$CLASH"for path-scoped cleanup.