From bab4fb9b7bb530ac4d9bf60ba5096fccf23b6e87 Mon Sep 17 00:00:00 2001 From: Amit Maurya Date: Wed, 25 Feb 2026 15:51:27 +0530 Subject: [PATCH] fix: prevent gateway double-spawn when process undetected by listProcesses() Fixes #289 Two changes to avoid the "gateway already running / port in use" error that occurs when the container already has a running gateway that findExistingMoltbotProcess() fails to detect: 1. Broaden command matching to also check for `/usr/local/bin/start-openclaw.sh` (full path), so invocations via `bash /usr/local/bin/start-openclaw.sh` are recognised. 2. Add a TCP port pre-check in ensureMoltbotGateway() before spawning. If port 18789 is already listening, the gateway is up regardless of what listProcesses() returned, so we skip the spawn entirely. --- src/gateway/process.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/gateway/process.ts b/src/gateway/process.ts index 571719e3b..238c2b267 100644 --- a/src/gateway/process.ts +++ b/src/gateway/process.ts @@ -19,6 +19,8 @@ export async function findExistingMoltbotProcess(sandbox: Sandbox): Promise /dev/tcp/localhost/${MOLTBOT_PORT}' 2>/dev/null && echo 'open' || echo 'closed'`, + ); + if (portCheck.stdout?.trim() === 'open') { + console.log(`Port ${MOLTBOT_PORT} already open — gateway running but undetected, skipping spawn`); + const procs = await sandbox.listProcesses(); + const any = procs.find((p) => p.status === 'running' || p.status === 'starting'); + if (any) return any; + } + } catch { + // Port probe failed — proceed to start normally + } + // Start a new OpenClaw gateway console.log('Starting new OpenClaw gateway...'); const envVars = buildEnvVars(env);