Skip to content

[Bug] Orphan clash processes accumulate across restarts — memory leak #5215

Description

@fqscfqj

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

  1. Start OpenClash normally
  2. Run /etc/init.d/openclash restart 3 times in succession
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions