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

Function assertPortsFree

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

Source from the content-addressed store, hash-verified

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