MCPcopy Create free account
hub / github.com/cortexkit/magic-context / pickFreePort

Function pickFreePort

packages/e2e-tests/src/opencode-runner/spawn.ts:60–66  ·  view source on GitHub ↗

* Pick a random free port by asking the OS for one. Uses Bun.serve + immediate stop.

()

Source from the content-addressed store, hash-verified

58 * Pick a random free port by asking the OS for one. Uses Bun.serve + immediate stop.
59 */
60async function pickFreePort(): Promise<number> {
61 const server = Bun.serve({ port: 0, fetch: () => new Response() });
62 const port: number = server.port ?? 0;
63 server.stop(true);
64 if (!port) throw new Error("could not allocate a free port");
65 return port;
66}
67
68/**
69 * Create isolated config/data/cache dirs under a unique temp subdir.

Callers 1

spawnOpencodeFunction · 0.85

Calls 1

stopMethod · 0.65

Tested by

no test coverage detected