Skip to content

Commit 658de1b

Browse files
sohail2721claude
andcommitted
fix(portal): handle a failed live-reload server bind gracefully
livereload binds its own internal HTTP server and only error-handles the WebSocket server, so a taken live-reload port (race after get-port) emitted an unhandled "error" and crashed the CLI. Wait on livereload's internal HTTP server (config.server) right after creation and fail cleanly with serverStartFailed, mirroring the main server's bind handling. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 1c9978d commit 658de1b

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/actions/portal/serve.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,22 @@ export class PortalServeAction {
7070

7171
const liveReloadPort = await this.networkService.getServerPort([35729, 35730, 35731, 35732]);
7272
const liveReloadServer = createLiveReloadServer({ port: liveReloadPort });
73+
74+
// get-port only checks availability; a port can be taken between that check and the
75+
// actual bind, so wait for each server to bind and fail cleanly instead of letting an
76+
// unhandled "error" event crash the CLI. livereload surfaces its bind error only on
77+
// its internal HTTP server (config.server), which isn't part of its public type.
78+
const liveReloadHttpServer = (liveReloadServer as unknown as { config: { server: Server } }).config.server;
79+
if ((await this.waitForServerListening(liveReloadHttpServer)).isErr()) {
80+
this.prompts.serverStartFailed(liveReloadPort);
81+
return ActionResult.failed();
82+
}
83+
7384
const server = this.application
7485
.use(connectLiveReload())
7586
.use(express.static(portalDirectory.toString(), { extensions: ["html"] }))
7687
.listen(servePort);
7788

78-
// get-port only checks availability; the port can be taken between that check and
79-
// now, so handle a failed bind gracefully instead of letting an unhandled "error"
80-
// event crash the CLI.
8189
const listenResult = await this.waitForServerListening(server);
8290
if (listenResult.isErr()) {
8391
liveReloadServer.close();

0 commit comments

Comments
 (0)