{"record":{"id":"52a95b4acd392d52","repo":"vercel/next.js","slug":"port-port-is-already-serving-responses-anothe","errorCode":null,"errorMessage":"Port ${port} is already serving responses — another server is running. Stop it or pass a different --port.","messagePattern":"Port (.+?) is already serving responses — another server is running\\. Stop it or pass a different --port\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"bench/render-pipeline/benchmark.ts","lineNumber":344,"sourceCode":"}\n\n// The death check alone is racy on a contested port: a stale server can\n// answer the readiness probe before our child fails to bind, and the run\n// would silently measure the wrong server.\nasync function assertPortFree(port: number): Promise<void> {\n  const controller = new AbortController()\n  const timeout = setTimeout(() => controller.abort(), 1000)\n  try {\n    await fetch(`http://127.0.0.1:${port}/`, {\n      cache: 'no-store',\n      signal: controller.signal,\n    })\n  } catch {\n    return\n  } finally {\n    clearTimeout(timeout)\n  }\n  throw new Error(\n    `Port ${port} is already serving responses — another server is running. ` +\n      `Stop it or pass a different --port.`\n  )\n}\n\n// Reads the body as a stream so TTFB (first body chunk) can be observed\n// separately from total latency. Byte counts are of the decompressed body.\nasync function measureRequest(\n  url: string,\n  timeoutMs: number\n): Promise<RequestSample> {\n  const controller = new AbortController()\n  const timeout = setTimeout(() => controller.abort(), timeoutMs)\n\n  try {\n    const start = performance.now()\n    const response = await fetch(url, {\n      cache: 'no-store',","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/bench/render-pipeline/benchmark.ts#L326-L362","documentation":"Thrown by assertPortFree (benchmark.ts:344) when a pre-flight probe to http://127.0.0.1:{port}/ succeeds (returns a response) before the benchmark spawns its own server. This is a deliberate guard against the contested-port race: if something is already answering on the port, spawning our server would either fail to bind or — worse — silently let the readiness probe hit the wrong server, corrupting measurements. assertPortFree is called at the start of each session (runMinimalServerSession, runE2EServerSession).","triggerScenarios":"Any HTTP response comes back from 127.0.0.1:{port} within the 1s AbortController window before the benchmark starts its server: a leftover `next start`, another benchmark process, a dev server, or an unrelated service on that port. The probe treats any successful fetch (any status) as 'port is serving'.","commonSituations":"A previous benchmark run didn't clean up its server (crashed mid-run); user has their own dev server on 3199; port recycled from another tool; running two benchmark instances concurrently.","solutions":["Stop whatever is serving on the port (the message's instruction), then re-run.","Pass a different --port to sidestep the conflict.","Find the holder: lsof -i :{port} / ss -ltnp 'sport = :{port}' and kill it.","Ensure prior runs exit cleanly so they don't leak servers; avoid running two benchmarks on the same port."],"exampleFix":"# before — stale server on 3199 trips the pre-flight check\n#   pnpm bench:render-pipeline --port=3199\n#   -> Port 3199 is already serving responses ...\n\n# fix — use a free port (or stop the holder first)\n#   pnpm bench:render-pipeline --port=3211","handlingStrategy":"validation","validationCode":"import { createConnection } from 'node:net'\nasync function isPortServing(port: number): Promise<boolean> {\n  return new Promise((resolveFn) => {\n    const sock = createConnection({ port, host: '127.0.0.1' })\n    sock.on('connect', () => { sock.destroy(); resolveFn(true) })\n    sock.on('error', () => resolveFn(false))\n  })\n}\nif (await isPortServing(port)) throw new Error(`Port ${port} is already in use; pick another via --port`)","typeGuard":"function isPortBusyError(err: unknown): boolean {\n  return err instanceof Error && /already serving responses/.test(err.message)\n}","tryCatchPattern":"// the guard fires before spawn; you usually surface and exit:\ntry {\n  await assertPortFree(options.port)\n} catch (err) {\n  if (isPortBusyError(err)) {\n    console.error((err as Error).message)\n    console.error(`Find holder: lsof -i :${options.port}  (or: ss -ltnp 'sport = :${options.port}')`)\n    process.exit(2)\n  }\n  throw err\n}","preventionTips":["Always pass a known-free --port, especially in CI where ports persist across jobs.","Kill servers in finally blocks so crashed runs don't leave listeners.","Never run two benchmark instances on the same port.","lsof/ss the port quickly when this fires to find and stop the holder."],"tags":["server","port-conflict","render-pipeline","pre-flight","benchmark"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}