{ "title": "Gateway lock", "content": "Last updated: 2025-12-11\n\n* Ensure only one gateway instance runs per base port on the same host; additional gateways must use isolated profiles and unique ports.\n* Survive crashes/SIGKILL without leaving stale lock files.\n* Fail fast with a clear error when the control port is already occupied.\n\n* The gateway binds the WebSocket listener (default `ws://127.0.0.1:18789`) immediately on startup using an exclusive TCP listener.\n* If the bind fails with `EADDRINUSE`, startup throws `GatewayLockError(\"another gateway instance is already listening on ws://127.0.0.1:\")`.\n* The OS releases the listener automatically on any process exit, including crashes and SIGKILL—no separate lock file or cleanup step is needed.\n* On shutdown the gateway closes the WebSocket server and underlying HTTP server to free the port promptly.\n\n* If another process holds the port, startup throws `GatewayLockError(\"another gateway instance is already listening on ws://127.0.0.1:\")`.\n* Other bind failures surface as `GatewayLockError(\"failed to bind gateway socket on ws://127.0.0.1:: …\")`.\n\n* If the port is occupied by *another* process, the error is the same; free the port or choose another with `openclaw gateway --port `.\n* The macOS app still maintains its own lightweight PID guard before spawning the gateway; the runtime lock is enforced by the WebSocket bind.", "code_samples": [], "headings": [ { "level": "h2", "text": "Why", "id": "why" }, { "level": "h2", "text": "Mechanism", "id": "mechanism" }, { "level": "h2", "text": "Error surface", "id": "error-surface" }, { "level": "h2", "text": "Operational notes", "id": "operational-notes" } ], "url": "llms-txt#gateway-lock", "links": [] }