MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / freePort

Function freePort

e2e/src/vm/tart.ts:68–76  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

66
67/** Ask the OS for a free localhost port (for SSH tunnels). */
68const freePort = (): Promise<number> =>
69 new Promise((resolve, reject) => {
70 const srv = net.createServer();
71 srv.on("error", reject);
72 srv.listen(0, "127.0.0.1", () => {
73 const port = (srv.address() as net.AddressInfo).port;
74 srv.close(() => resolve(port));
75 });
76 });
77
78/** Resolve once a TCP connect to localhost:port succeeds (SSH bound the forward). */
79const waitLocalPort = async (port: number, attempts = 40): Promise<void> => {

Callers 1

tartVmFunction · 0.70

Calls 4

listenMethod · 0.80
addressMethod · 0.80
closeMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected