fix: Host API port conflict crashing startup on Windows (#743)

This commit is contained in:
paisley
2026-04-02 12:00:43 +08:00
committed by GitHub
Unverified
parent 06266cb4d2
commit 7e2c4d3835
8 changed files with 32 additions and 20 deletions

View File

@@ -43,7 +43,7 @@ const routeHandlers: RouteHandler[] = [
* Per-session secret token used to authenticate Host API requests.
* Generated once at server start and shared with the renderer via IPC.
* This prevents cross-origin attackers from reading sensitive data even
* if they can reach 127.0.0.1:3210 (the CORS wildcard alone is not
* if they can reach 127.0.0.1:13210 (the CORS wildcard alone is not
* sufficient because browsers attach the Origin header but not a secret).
*/
let hostApiToken: string = '';
@@ -106,6 +106,18 @@ export function startHostApiServer(ctx: HostApiContext, port = getPort('CLAWX_HO
}
});
server.on('error', (error: NodeJS.ErrnoException) => {
if (error.code === 'EACCES' || error.code === 'EADDRINUSE') {
logger.error(
`Host API server failed to bind port ${port}: ${error.message}. ` +
'On Windows this is often caused by Hyper-V reserving the port range. ' +
`Set CLAWX_PORT_CLAWX_HOST_API env var to override the default port.`,
);
} else {
logger.error('Host API server error:', error);
}
});
server.listen(port, '127.0.0.1', () => {
logger.info(`Host API server listening on http://127.0.0.1:${port}`);
});

View File

@@ -14,7 +14,7 @@ export const PORTS = {
CLAWX_GUI: 23333,
/** Local host API server port */
CLAWX_HOST_API: 3210,
CLAWX_HOST_API: 13210,
/** OpenClaw Gateway port */
OPENCLAW_GATEWAY: 18789,