Skip to content

Commit 0ce3bc5

Browse files
filiptronicekjeanp413
authored andcommitted
Terminate the server if the port is not available
1 parent 2f59384 commit 0ce3bc5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/vs/server/node/server.main.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,12 +1014,19 @@ export async function main(options: IServerOptions): Promise<void> {
10141014
} else if (typeof options.port === 'number') {
10151015
port = options.port;
10161016
}
1017+
10171018
const host = parsedArgs.host || '0.0.0.0';
1019+
server.on('error', () => {
1020+
server.close();
1021+
process.exit(1);
1022+
});
1023+
10181024
server.listen(port, host, () => {
10191025
const addressInfo = server.address() as net.AddressInfo;
10201026
const address = addressInfo.address === '0.0.0.0' || addressInfo.address === '127.0.0.1' ? 'localhost' : addressInfo.address;
1021-
const port = addressInfo.port === 80 ? '' : String(addressInfo.port);
1022-
logService.info(`Web UI available at http://${address}:${port}`);
1027+
const formattedPort = addressInfo.port === 80 ? '' : String(addressInfo.port);
1028+
logService.info(`Web UI available at http://${address}:${formattedPort}`);
10231029
});
1030+
10241031
});
10251032
}

0 commit comments

Comments
 (0)