jlcodes99/cockpit-tools · error

[WS] 无法绑定端口 ({}-{}),最后错误: {}

Error message

[WS] 无法绑定端口 ({}-{}),最后错误: {}

What it means

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.

Source

Thrown at crates/cockpit-core/src/modules/websocket.rs:482

    for attempt in 0..PORT_RANGE {
        let addr = format!("0.0.0.0:{}", port);
        match TcpListener::bind(&addr).await {
            Ok(l) => {
                listener = Some(l);
                if attempt > 0 {
                    crate::modules::logger::log_info(&format!(
                        "[WS] 配置端口 {} 被占用,使用端口: {}",
                        preferred_port, port
                    ));
                }
                break;
            }
            Err(e) => {
                if attempt < PORT_RANGE - 1 {
                    port += 1;
                } else {
                    crate::modules::logger::log_error(&format!(
                        "[WS] 无法绑定端口 ({}-{}),最后错误: {}",
                        preferred_port,
                        preferred_port + PORT_RANGE - 1,
                        e
                    ));
                    return;
                }
            }
        }
    }

    let listener = match listener {
        Some(l) => l,
        None => return,
    };

    // 保存服务状态到共享文件(供 VS Code 扩展读取)
    if let Err(e) = init_server_status(port) {

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Check the last OS error — EACCES (privileged port) or EADDRINUSE (range fully occupied) point to different fixes
  2. Free ports in the configured range or widen PORT_RANGE/firewall exceptions
  3. Verify no orphaned previous instance is squatting on the whole range
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at crates/cockpit-core/src/modules/websocket.rs:482 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05). Data as JSON: /api/errors/069ebade21643c1e. Report an issue: GitHub.