-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Problem
When the OpenClaw gateway is already running inside the container (e.g. started automatically on container boot), ensureMoltbotGateway can fail to detect it via sandbox.listProcesses() and attempts to spawn a second instance, resulting in:
Gateway failed to start: gateway already running (pid 402); lock timeout after 5000ms
Port 18789 is already in use.
Root Cause
findExistingMoltbotProcess matches command strings like start-openclaw.sh and openclaw gateway, but the sandbox process list may expose the process as bash /usr/local/bin/start-openclaw.sh (with full path and shell prefix), which the current string-matching misses.
Fix
Two changes:
-
Broaden command matching — also match
/usr/local/bin/start-openclaw.sh(full path) so bash-invoked scripts are detected correctly. -
Port pre-check before spawning — before starting a new process, check if port
18789is already listening via a TCP probe. If it is, skip the spawn entirely even iflistProcessesreturned nothing useful. This acts as a safety net against any future process-detection gaps.
Steps to Reproduce
- Deploy to Cloudflare Workers with Sandbox
- Let the container start and the gateway boot
- Trigger a new request that calls
ensureMoltbotGateway - Observe the "gateway already running" / "port in use" error in logs