Bug Description
When openclaw-gateway restarts or exits unexpectedly, the Chromium browser processes spawned for headless browsing are not properly terminated. These processes become orphaned (parent PID becomes 1) and continue running indefinitely, accumulating renderer processes and consuming significant memory over time.
Environment
- OS: Linux 5.15.0-46-generic (x64)
- OpenClaw Version: 2026.2.2-3 (also confirmed in 2026.2.6-3)
- Node.js: v24.13.0
- Browser: Chromium (snap) with
--remote-debugging-port=9222
Steps to Reproduce
- Start
openclaw-gateway with browser enabled (browser.enabled: true in config)
- Let the gateway run for some time (browser will be spawned)
- Restart the gateway (
openclaw gateway restart) or let it crash
- Observe that old Chromium processes are not terminated
Observed Behavior
After running for 8 days, the following was observed:
# Main Chromium process became orphaned (PPID = 1, started Jan 30)
root 2974010 1 0 Jan30 ? 01:30:08 /snap/chromium/.../chrome --headless --remote-debugging-port=9222 ...
# Multiple renderer processes accumulated, each consuming 100-200MB
root 1569768 ... 5.6% mem /snap/chromium/.../chrome --type=renderer ...
root 1322752 ... 5.2% mem /snap/chromium/.../chrome --type=renderer ...
root 1301273 ... 5.0% mem /snap/chromium/.../chrome --type=renderer ...
# ... 10+ renderer processes
Total memory consumed by orphaned browser processes: ~1.5GB
Root Cause Analysis
In chrome.ts, the browser is spawned using spawn():
return spawn(exe.path, args, {
stdio: "pipe",
env: { ...process.env, HOME: os.homedir() }
});
When the gateway process exits or restarts:
- The spawned Chrome process is not killed
- Chrome becomes an orphan process (reparented to PID 1)
- Renderer child processes continue to accumulate
- Memory usage grows unbounded
Expected Behavior
When openclaw-gateway restarts or exits:
- All spawned browser processes should be terminated gracefully
- A cleanup handler should kill any lingering Chrome processes on the configured CDP port
- On startup, the gateway should detect and clean up any orphaned browser processes from previous runs
Suggested Fixes
-
Add process cleanup on exit: Register process.on('exit') and process.on('SIGTERM') handlers to call stopOpenClawChrome()
-
Startup cleanup: On gateway start, check if port 9222 is in use by an orphaned Chrome process and kill it
-
Process group management: Consider using detached: false and managing the process group to ensure child processes are cleaned up
Workaround
Currently using a cron job to restart the gateway daily:
0 19 * * * openclaw gateway restart >> /var/log/openclaw-restart.log 2>&1
And manually killing orphaned processes:
pkill -9 -f "chromium.*--remote-debugging-port=9222"
Bug Description
When
openclaw-gatewayrestarts or exits unexpectedly, the Chromium browser processes spawned for headless browsing are not properly terminated. These processes become orphaned (parent PID becomes 1) and continue running indefinitely, accumulating renderer processes and consuming significant memory over time.Environment
--remote-debugging-port=9222Steps to Reproduce
openclaw-gatewaywith browser enabled (browser.enabled: truein config)openclaw gateway restart) or let it crashObserved Behavior
After running for 8 days, the following was observed:
Total memory consumed by orphaned browser processes: ~1.5GB
Root Cause Analysis
In
chrome.ts, the browser is spawned usingspawn():When the gateway process exits or restarts:
Expected Behavior
When
openclaw-gatewayrestarts or exits:Suggested Fixes
Add process cleanup on exit: Register
process.on('exit')andprocess.on('SIGTERM')handlers to callstopOpenClawChrome()Startup cleanup: On gateway start, check if port 9222 is in use by an orphaned Chrome process and kill it
Process group management: Consider using
detached: falseand managing the process group to ensure child processes are cleaned upWorkaround
Currently using a cron job to restart the gateway daily:
And manually killing orphaned processes:
pkill -9 -f "chromium.*--remote-debugging-port=9222"