Gateway / 运用 • TutorialHeader.readTime
Gateway 锁
WebSocket 监听器的绑定由 Gateway 的单一运行守卫
最終更新:2025-12-11
Tutorial.step
Why
- 确保同一主机上每个基础端口只运行一个网关实例;额外的网关必须使用隔离的配置文件和唯一端口。
- Survive crashes/SIGKILL without leaving stale lock files.
- 控制端口但占有如果已被在、明確那错误在即座在失败执行。
Tutorial.step
仕組见
- Gateway 是起動直後在排他的那 TCP 监听器在 WebSocket 监听器绑定执行(默认
ws://127.0.0.1:18789)。 - 如果绑定失败并显示 <code>EADDRINUSE</code>,启动会抛出 <code>GatewayLockError("another gateway instance is already listening on ws://127.0.0.1:<port>")</code>。
- The OS releases the listener automatically on any process exit, including crashes and SIGKILL—no separate lock file or cleanup step is needed.
- 结束時是 WebSocket 服务器和下層的 HTTP 服务器闭自、端口即時解放执行。
Tutorial.step
错误的表面
- 如果另一个进程占用了端口,启动会抛出 <code>GatewayLockError("another gateway instance is already listening on ws://127.0.0.1:<port>")</code>。
- 那个他的绑定失败是 <code>GatewayLockError("failed to bind gateway socket on ws://127.0.0.1:<port>: …")</code> 作为表面化执行。
Tutorial.step
运维上的注意
- 如果端口被其他进程占用,错误是相同的;释放端口或使用 <code>openclaw gateway --port <port>'</code> 选择另一个端口。
- The macOS app still maintains its own lightweight PID guard before spawning the gateway; the runtime lock is enforced by the WebSocket bind.