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

Function assertPortsFree

scripts/dev-safe.mjs:256–275  ·  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
268 .map(({ name, port }) => ` • ${name}: port ${port}`)
269 .join("\n");
270 throw new Error(
271 `Cannot start: the following ports are already in use:\n\n${lines}\n\n` +
272 `Another agent-canvas instance may already be running.\n` +
273 `Stop it first, or override the port via environment variables (e.g. PORT=<other>).`,
274 );
275}
276
277/**
278 * 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