{"record":{"id":"5d01078cc1f87cba","repo":"remix-run/react-router","slug":"no-available-port-found","errorCode":null,"errorMessage":"No available port found","messagePattern":"No available port found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/react-router-serve/cli.ts","lineNumber":80,"sourceCode":"  );\n}\n\nfunction parseNumber(raw?: string) {\n  if (raw === undefined) return undefined;\n  let maybe = Number(raw);\n  if (Number.isNaN(maybe)) return undefined;\n  return maybe;\n}\n\nasync function getAvailablePort(\n  preferredPort: number,\n  host?: string,\n): Promise<number> {\n  let preferredAvailablePort = await checkPort(preferredPort, host);\n  let availablePort = preferredAvailablePort ?? (await checkPort(0, host));\n\n  if (availablePort === undefined) {\n    throw new Error(\"No available port found\");\n  }\n\n  return availablePort;\n}\n\nfunction checkPort(port: number, host?: string): Promise<number | undefined> {\n  return new Promise((resolve, reject) => {\n    let server = net.createServer();\n    let listenOptions = host ? { port, host } : { port };\n\n    server.unref();\n\n    server.once(\"error\", (error: NodeJS.ErrnoException) => {\n      if (error.code === \"EADDRINUSE\" || error.code === \"EACCES\") {\n        resolve(undefined);\n      } else {\n        reject(error);\n      }","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/remix-run/react-router/blob/6beaca39526d5716c3c112ebb0782765baa5a9ce/packages/react-router-serve/cli.ts#L62-L98","documentation":"@react-router/serve's CLI resolves its listen port by probing the preferred port and then an ephemeral port (0). checkPort resolves undefined for EADDRINUSE and EACCES — skipping to the next candidate — and the fallback to port 0 normally always succeeds. 'No available port found' means even the ephemeral probe came back undefined, i.e. the process is denied socket binding outright (permission-denied on every attempt) in the current environment.","triggerScenarios":"Running react-router-serve in an environment where net.createServer().listen() fails with EACCES for both the preferred port and port 0 — e.g. a locked-down container/sandbox without network capabilities, or an OS policy denying socket creation.","commonSituations":"Hardened Docker/Kubernetes containers (network caps dropped), gVisor/Firecracker sandboxes, SELinux/AppArmor policies, CI runners with networking restricted, or non-root users denied socket ops.","solutions":["Relax the sandbox: run the container with default network capabilities instead of --cap-drop ALL style lockdown","Check SELinux/AppArmor or firewall policy for socket-bind denials for the node process","If you only meant to change interfaces, verify the --host value is an address this machine actually owns"],"exampleFix":"# before — binding denied by container lockdown\ndocker run --cap-drop ALL --network none my-app \\\n  npx react-router-serve ./build/server/index.js\n\n# after — allow basic networking\ndocker run my-app \\\n  npx react-router-serve ./build/server/index.js","handlingStrategy":"retry","validationCode":"// probe candidates (incl. ephemeral) before handing off to the server\nimport net from \"node:net\";\nfunction probe(port: number, host?: string): Promise<number | undefined> {\n  return new Promise((resolve) => {\n    const s = net.createServer();\n    s.once(\"error\", () => resolve(undefined));\n    s.listen(host ? { port, host } : { port }, () => {\n      const addr = s.address();\n      s.close(() => resolve(typeof addr === \"object\" && addr ? addr.port : undefined));\n    });\n  });\n}\nif ((await probe(0, host)) === undefined) {\n  throw new Error(\"socket binding denied in this environment — fix sandbox/network policy\");\n}","typeGuard":null,"tryCatchPattern":"// your own server bootstrap: walk candidate ports, treat denial separately\nfor (const port of [Number(process.env.PORT) || 3000, 3001, 0]) {\n  try {\n    await listen(port, host);\n    break;\n  } catch (err) {\n    const code = (err as NodeJS.ErrnoException).code;\n    if (code !== \"EADDRINUSE\") throw err; // EACCES/EADDRNOTAVAIL need a host/env fix, not a retry\n  }\n}","preventionTips":["Don't drop all network capabilities from containers that must serve HTTP","Verify --host is an address the machine owns before binding","Probe with port 0 in a preflight step to detect binding denial early"],"tags":["serve","port","network","binding","cli","permissions"],"backgroundTag":"port-binding-failed","analyzedSha":"6beaca39526d5716c3c112ebb0782765baa5a9ce","analyzedAt":"2026-08-18T18:04:14.938Z","contentChangedAt":"2026-08-18T18:04:14.938Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}