{"record":{"id":"f88215966389257e","repo":"pbakaus/impeccable","slug":"error-listen-eaddrinuse-address-already-in-use-1","errorCode":null,"errorMessage":"Error: listen EADDRINUSE: address already in use 127.0.0.1:{port} ({err})\n","messagePattern":"Error: listen EADDRINUSE: address already in use 127\\.0\\.0\\.1:(.+?) \\((.+?)\\)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/live/src/live_server.rs","lineNumber":277,"sourceCode":"                    removed\n                ));\n            }\n        }\n        st.restore_pending_events_from_store();\n        manual_apply::prune_stale_evidence(&st);\n    }\n\n    // Port\n    let port_arg = argv.iter().find(|a| a.starts_with(\"--port=\"));\n    let listener = match port_arg {\n        Some(a) => {\n            let raw = a.splitn(2, '=').nth(1).unwrap_or(\"\");\n            let p = impeccable_core::js::parse_int(raw, 10);\n            let port = if p.is_nan() { 0u16 } else { p as u16 };\n            match TcpListener::bind((\"127.0.0.1\", port)) {\n                Ok(l) => l,\n                Err(e) => {\n                    io.err(&format!(\n                        \"Error: listen EADDRINUSE: address already in use 127.0.0.1:{} ({})\\n\",\n                        port, e\n                    ));\n                    return 1;\n                }\n            }\n        }\n        None => {\n            let mut port: u16 = 8400;\n            loop {\n                match TcpListener::bind((\"127.0.0.1\", port)) {\n                    Ok(l) => break l,\n                    Err(_) => {\n                        if port == u16::MAX {\n                            io.err(\"Error: no free port\\n\");\n                            return 1;\n                        }\n                        port += 1;","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/pbakaus/impeccable/blob/2bc2879276c1f321a53c4ca99d3371e411329b52/crates/live/src/live_server.rs#L259-L295","documentation":"When the live server is started with an explicit `--port=N` argument, it binds a TcpListener to 127.0.0.1:N. If the bind fails, it prints this EADDRINUSE-style message — including the OS error text as `{err}` — and exits 1. Unlike the auto port scan, an explicit port is never silently moved.","triggerScenarios":"`live-server --port=N` (args parsed as `port=N`) where `TcpListener::bind((\"127.0.0.1\", port))` returns Err — another process (often a previous live server) already holds port N. Note bind errors other than EADDRINUSE also land here, with the real OS error in `{err}`.","commonSituations":"Passing a fixed --port that a previous live-server instance still occupies; another dev tool on the same machine using the requested port; container port mappings conflicting with the loopback bind; a non-numeric --port value parsing as NaN and falling back to port 0 handling.","solutions":["Pick a different --port value that is free, or omit --port to let the server auto-scan from 8400.","Stop the process holding the port: `<self_cmd> live-server stop`, or `lsof -i :<port>` / `ss -ltnp` to find and kill the occupier.","Read the `{err}` portion of the message to confirm it is genuinely EADDRINUSE and not a permission problem (e.g. privileged port)."],"exampleFix":"// before\n$ impeccable live-server --port=8400\nError: listen EADDRINUSE: address already in use 127.0.0.1:8400 (Address already in use (os error 98))\n// after\n$ impeccable live-server --port=8401   # or omit --port for auto-scan","handlingStrategy":"validation","validationCode":"// shell: verify the requested port is free before passing --port\nport=8400\nif [ -n \"$WANTED_PORT\" ]; then\n  if ss -ltn \"sport = :$WANTED_PORT\" | grep -q LISTEN; then echo \"port $WANTED_PORT busy\" >&2; exit 2; fi\n  PORT_ARG=\"--port=$WANTED_PORT\"\nfi\nimpeccable live-server $PORT_ARG","typeGuard":null,"tryCatchPattern":"// on EADDRINUSE, drop the explicit port and retry with auto-scan\ntry {\n  execSync('impeccable live-server --port=8400');\n} catch (e) {\n  if (/EADDRINUSE/.test(String(e.stderr))) execSync('impeccable live-server');\n  else throw e;\n}","preventionTips":["Prefer the default auto-scan over hardcoding --port.","Before using a fixed port, check it with `ss -ltn` / `lsof -i :<port>`.","Stop previous live-server instances before reusing the same port."],"tags":["network","port-conflict","tcp"],"backgroundTag":"address-already-in-use","analyzedSha":"2bc2879276c1f321a53c4ca99d3371e411329b52","analyzedAt":"2026-09-08T04:51:14.109Z","contentChangedAt":"2026-09-08T04:51:14.109Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}