INNER CODE UNIT · JavaScript

findAvailablePort

aeonfun/opendia · opendia-mcp/server.js:109

async function findAvailablePort(startPort) {
  let port = startPort;
  while (await checkPortInUse(port)) {
    port++;
    if (port > startPort + 100) { // Safety limit
      throw new Error(`Could not find available port after checking ${port - startPort} ports`);
    }
  }
  return port;
}

async function killExistingOpenDia(port) {
  return new Promise((resolve) => {
    exec(`lsof -ti:${port}`, async (error, stdout) => {
      if (error || !stdout.trim()) {
        resolve(false);
        return;
      }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…