{"record":{"id":"03c66b12883c9404","repo":"vercel/next.js","slug":"port-port-is-already-serving-responses-anothe-03c66b","errorCode":null,"errorMessage":"Port ${port} is already serving responses — another server is running. Stop it, pass a different --port, or use --start-server=false to trace against it deliberately.","messagePattern":"Port (.+?) is already serving responses — another server is running\\. Stop it, pass a different --port, or use --start-server=false to trace against it deliberately\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"bench/render-pipeline/client-trace.ts","lineNumber":266,"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, pass a different --port, or use --start-server=false to ` +\n      `trace against it deliberately.`\n  )\n}\n\nasync function gracefulKill(server: ReturnType<typeof spawn>) {\n  // once('exit') never resolves for a child that already exited.\n  if (server.exitCode !== null || server.signalCode !== null) return\n  const tryKill = async (signal: NodeJS.Signals, timeoutMs: number) => {\n    server.kill(signal)\n    const didExit = await Promise.race([\n      once(server, 'exit')\n        .then(() => true)\n        .catch(() => true),\n      sleep(timeoutMs).then(() => false),\n    ])\n    return didExit","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/bench/render-pipeline/client-trace.ts#L248-L284","documentation":"Thrown by assertPortFree before starting a server when an HTTP GET to http://127.0.0.1:{port}/ already returns a response. This prevents the contested-port race where a stale server answers the readiness probe while the new child fails to bind, causing the tracer to silently measure the wrong (old) server. The error message offers three explicit escapes.","triggerScenarios":"A previous next dev/start (or any HTTP server) is still bound to the port; a different benchmark left a process running; an unrelated dev server (Vite, Express) occupies the port.","commonSituations":"Iterating on benchmarks without killing the prior server; a crashed benchmark left an orphan server; running multiple trace jobs concurrently on the default port.","solutions":["Stop the existing server: lsof -ti:PORT | xargs kill, or close the dev terminal.","Pass a different --port that is free.","Pass --start-server=false to deliberately trace against the already-running server (you accept it is the target)."],"exampleFix":"# before: port busy, ambiguous target\npnpm bench:render-pipeline:client --port=3199\n\n# after: free the port first\nlsof -ti:3199 | xargs kill -9\npnpm bench:render-pipeline:client --port=3199","handlingStrategy":"validation","validationCode":"// Reuse the tracer's own logic: if something answers, decide deliberately\nasync function portHasServer(port: number): Promise<boolean> {\n  try {\n    await fetch(`http://127.0.0.1:${port}/`, { signal: AbortSignal.timeout(1000) })\n    return true\n  } catch { return false }\n}\nif (await portHasServer(port) && !options.attachToExisting) {\n  throw new Error(`Stop the server on ${port} or pass a different --port`)\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Kill prior servers between benchmark runs.","Use --start-server=false only when deliberately attaching to a known server.","Vary --port across concurrent benchmark jobs."],"tags":["server","port-conflict","validation"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}