{"record":{"id":"069ebade21643c1e","repo":"jlcodes99/cockpit-tools","slug":"ws","errorCode":null,"errorMessage":"[WS] 无法绑定端口 ({}-{})，最后错误: {}","messagePattern":"\\[WS\\] 无法绑定端口 \\((.+?)-(.+?)\\)，最后错误: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cockpit-core/src/modules/websocket.rs","lineNumber":482,"sourceCode":"\n    for attempt in 0..PORT_RANGE {\n        let addr = format!(\"0.0.0.0:{}\", port);\n        match TcpListener::bind(&addr).await {\n            Ok(l) => {\n                listener = Some(l);\n                if attempt > 0 {\n                    crate::modules::logger::log_info(&format!(\n                        \"[WS] 配置端口 {} 被占用，使用端口: {}\",\n                        preferred_port, port\n                    ));\n                }\n                break;\n            }\n            Err(e) => {\n                if attempt < PORT_RANGE - 1 {\n                    port += 1;\n                } else {\n                    crate::modules::logger::log_error(&format!(\n                        \"[WS] 无法绑定端口 ({}-{})，最后错误: {}\",\n                        preferred_port,\n                        preferred_port + PORT_RANGE - 1,\n                        e\n                    ));\n                    return;\n                }\n            }\n        }\n    }\n\n    let listener = match listener {\n        Some(l) => l,\n        None => return,\n    };\n\n    // 保存服务状态到共享文件（供 VS Code 扩展读取）\n    if let Err(e) = init_server_status(port) {","sourceCodeStart":464,"sourceCodeEnd":500,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/crates/cockpit-core/src/modules/websocket.rs#L464-L500","documentation":"Port-allocation exhaustion error in the websocket module: the listener tried binding every port in the preferred range (PORT_RANGE attempts, incrementing from the configured port) and all TcpListener::bind calls failed. The message '[WS] 无法绑定端口 ({}-{})，最后错误: {}' reports the probed range and the last OS error; the websocket server cannot start.","triggerScenarios":"Thrown at crates/cockpit-core/src/modules/websocket.rs:482 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the last OS error — EACCES (privileged port) or EADDRINUSE (range fully occupied) point to different fixes","Free ports in the configured range or widen PORT_RANGE/firewall exceptions","Verify no orphaned previous instance is squatting on the whole range"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1ed8b77992d62ca81fabf744deb0839ad361d5bf","analyzedAt":"2026-09-05T09:51:41.178Z","contentChangedAt":"2026-09-05T09:51:41.178Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}