OpenClaw Crashing: Fix Memory & Restart Issues
Diagnose and fix OOM kills, gateway restart loops, and memory leaks in long-running instances.
Overview
This guide covers diagnosing and fixing gateway restart issues and memory problems in OpenClaw. If your gateway keeps restarting or using too much memory, this guide will help.
Diagnosing Restarts
Start by checking the gateway status and logs:
# Check gateway status
openclaw gateway status
# View recent logs
openclaw logs --lines 100
# Follow logs in real-time
openclaw logs --followLook for patterns:
- Repeated crashes at specific times
- Errors before shutdown
- Memory warnings
- Port already in use errors
Out of Memory (OOM)
If the gateway is being killed by the system (OOM killer), you need to reduce memory usage:
1. Reduce Docker memory limit
deploy:
resources:
limits:
memory: 2G # Reduce from 4G2. Reduce context window
agents:
defaults:
model:
contextTokens: 50000 # Reduce from 2000003. Enable memory compaction
agents:
defaults:
compaction:
mode: "safeguard"
reserveTokensFloor: 240004. Check memory usage
# Docker
docker stats
# System
free -h
htopPort Conflicts
If you see "port already in use" errors:
Find what's using the port
# For port 3000
lsof -i :3000
# For port 18789
lsof -i :18789Stop the conflicting process
# Kill by PID
kill -9 <PID>
# Or stop the service
sudo systemctl stop openclawRestart gateway
openclaw gateway restartps aux | grep openclawService Issues
If OpenClaw is installed as a system service:
Check service status
sudo systemctl status openclaw-gateway
sudo journalctl -u openclaw-gateway -n 50Reinstall service
openclaw gateway install --force
openclaw gateway restartCheck config location
Service config is at ~/.openclaw/openclaw.json for your user, or ~openclaw/.openclaw/openclaw.json for the system service.
Prevention & Monitoring
Set up monitoring to catch issues early:
1. Health checks
# Check health
curl http://localhost:3000/api/health2. Add cron monitoring
# Check every 5 minutes
*/5 * * * * curl -sf http://localhost:3000/api/health || systemctl restart openclaw-gateway3. Set up logging
Ensure logging is enabled to diagnose issues after they happen:
logging:
level: info # or debug for more detail4. Use the doctor command
openclaw doctorThis checks for common issues and misconfigurations.