MCP child processes orphaned on restart — memory leak
Description
When MiMoCode restarts (crash, manual restart, or session end), child MCP processes are NOT terminated. They get reparented to PID 1 (systemd/init) and persist as orphans, consuming memory indefinitely.
Each restart leaks 2 processes (~81MB RAM). After multiple restarts in a session:
- 22 orphaned shell+MCP pairs = 1.7GB RAM wasted
- 47 total MCP processes visible (only 2 legitimate)
Reproduction
- Configure MCP servers in
mimocode.json(e.g., ariel-memory with Python stdio) - Start MiMoCode
- Restart MiMoCode 10+ times (e.g., during plugin/skill development)
- Check:
ps aux | grep mcp_server | wc -l→ shows 20+ processes - Check orphans:
ps -eo pid,ppid,comm | grep 'python3.*mcp_server' | awk '$2==1'→ lists orphans
Root Cause Analysis
MiMoCode spawns MCP servers via shell wrapper:
sh -c 'cd /path && python3 -m mcp_server.server --transport stdio'
Process chain: MiMoCode (Node.js) → sh (shell wrapper) → python3 (MCP server)
When MiMoCode exits/restarts:
- Node.js process dies
- Shell wrapper (
sh) reparented to PID 1 (systemd) - Python MCP server also reparented to PID 1
- New MiMoCode instance creates new MCP processes
- Old processes remain as orphans indefinitely
Each orphan pair costs ~81MB RAM (1MB shell + 80MB Python MCP server).
Expected Behavior
MCP child processes should be terminated when MiMoCode exits or restarts. Options:
- Use process group killing (
setsid+kill -- -PGID) - Track child PIDs and kill them in shutdown handler
- Use
prctl(PR_SET_PDEATHSIG, SIGTERM)in the MCP launcher so children die when parent dies
Actual Behavior
MCP child processes become orphans (PPID=1) and consume ~80MB each until manually killed or system reboot.
Environment
- MiMoCode version: v0.38.9
- OS: Debian 12 (Linux)
- Node.js: system Node
- MCP config: ariel-memory (Python, stdio), context-mode (Node, stdio)
- Install method: npm global (
npm install -g mimocode)
Workaround
Cron job to clean up orphaned MCP processes every 15 minutes:
#!/bin/bash
# Kill mcp_server processes orphaned to PID 1
ps -eo pid,ppid,comm | grep 'python3.*mcp_server' | awk '$2==1 {system("kill -9 " $1)}'
ps -eo pid,ppid,args | grep 'sh.*-c.*mcp_server' | awk '$2==1 {system("kill -9 " $1)}'
Impact
On a development VPS with frequent MiMoCode restarts (plugin development, debugging), this leaks ~1.7GB RAM per session. Without the workaround, the system runs out of memory within hours.