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

Function assertPortsFree

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

Source from the content-addressed store, hash-verified

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