MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / assertPortsFree

Function assertPortsFree

scripts/dev-safe.mjs:266–285  ·  view source on GitHub ↗
(portConfigs, host = "127.0.0.1")

Source from the content-addressed store, hash-verified

264 * @param {string} [host]
265 */
266export async function assertPortsFree(portConfigs, host = "127.0.0.1") {
267 const results = await Promise.all(
268 portConfigs.map(async ({ name, port }) => ({
269 name,
270 port,
271 free: await tryPort(port, host),
272 })),
273 );
274 const busy = results.filter(({ free }) => !free);
275 if (busy.length === 0) return;
276
277 const lines = busy
278 .map(({ name, port }) => ` • ${name}: port ${port}`)
279 .join("\n");
280 throw new Error(
281 `Cannot start: the following ports are already in use:\n\n${lines}\n\n` +
282 `Another agent-canvas instance may already be running.\n` +
283 `Stop it first, or override the port via environment variables (e.g. PORT=<other>).`,
284 );
285}
286
287/**
288 * Find multiple free ports at once, each preferring its specified default.

Callers 3

buildConfigFunction · 0.90
dev-safe.test.tsFile · 0.90
buildSafeDevConfigAsyncFunction · 0.85

Calls 1

tryPortFunction · 0.85

Tested by

no test coverage detected