{"record":{"id":"51b41bf24162c548","repo":"rustdesk/rustdesk-server","slug":"invalid-port","errorCode":null,"errorMessage":"Invalid port","messagePattern":"Invalid port","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/main.rs","lineNumber":31,"sourceCode":"        .format(opt_format)\n        .write_mode(WriteMode::Async)\n        .start()?;\n    let args = format!(\n        \"-c --config=[FILE] +takes_value 'Sets a custom config file'\n        -b, --bind=[IP] 'Sets the IP address to bind to (default: all interfaces)'\n        -p, --port=[NUMBER(default={RENDEZVOUS_PORT})] 'Sets the listening port'\n        -s, --serial=[NUMBER(default=0)] '[DEPRECATED] Sets configure update serial number'\n        -R, --rendezvous-servers=[HOSTS] '[DEPRECATED] Sets rendezvous servers, separated by comma'\n        -u, --software-url=[URL] '[DEPRECATED] Sets download url of RustDesk software of newest version'\n        -r, --relay-servers=[HOST] 'Sets the default relay servers, separated by comma'\n        -M, --rmem=[NUMBER(default={RMEM})] 'Sets UDP recv buffer size, set system rmem_max first, e.g., sudo sysctl -w net.core.rmem_max=52428800. vi /etc/sysctl.conf, net.core.rmem_max=52428800, sudo sysctl –p'\n        , --mask=[MASK] '[DEPRECATED] Determine if the connection comes from LAN, e.g. 192.168.0.0/16'\n        -k, --key=[KEY] 'Only allow the client with the same key'\",\n    );\n    init_args(&args, \"hbbs\", \"RustDesk ID/Rendezvous Server\");\n    let port = get_arg_or(\"port\", RENDEZVOUS_PORT.to_string()).parse::<i32>()?;\n    if port < 3 {\n        bail!(\"Invalid port\");\n    }\n    let bind_addr = parse_bind_address(&get_arg(\"bind\"))?;\n    let rmem = get_arg(\"rmem\").parse::<usize>().unwrap_or(RMEM);\n    let serial: i32 = get_arg(\"serial\").parse().unwrap_or(0);\n    crate::common::check_software_update();\n    RendezvousServer::start_with_bind(\n        bind_addr,\n        port,\n        serial,\n        &get_arg_or(\"key\", \"-\".to_owned()),\n        rmem,\n    )?;\n    Ok(())\n}\n","sourceCodeStart":13,"sourceCodeEnd":46,"githubUrl":"https://github.com/rustdesk/rustdesk-server/blob/a7736be5e40f85bfc141120dce587e836e5d4b80/src/main.rs#L13-L46","documentation":"hbbs validates the `--port` CLI argument after parsing it as i32; any value below 3 is rejected with this anyhow bail. Ports 0-2 are reserved system ports that a rendezvous server must never bind, so the process refuses to start rather than fail later at socket bind time. This is a fail-fast guard at startup in src/main.rs.","triggerScenarios":"Running `hbbs --port 0`, `--port 1`, or `--port 2` (or supplying `port` via the arg input the get_arg_or wrapper reads). Any parsed i32 < 3 triggers the bail before RendezvousServer::start_with_bind is called.","commonSituations":"Operators copying a config file where port was left at 0 to mean 'auto-assign'; docker-compose entries passing PORT=0 expecting dynamic allocation; typos like `--port 2` when intending 21116; scripts using port 1/2 for internal tests against hbbs.","solutions":["Pass a valid unprivileged port >= 3, e.g. --port 21116 (the default RENDEZVOUS_PORT).","Check container/orchestrator env: if port comes from an env var, verify it is non-empty and numeric and >= 3 before launching hbbs.","If you intended dynamic port assignment, pick a concrete port instead - hbbs does not support port 0 auto-selection."],"exampleFix":"// before\nhbbs --port 0\n// after\nhbbs --port 21116","handlingStrategy":"validation","validationCode":"let port: i32 = std::env::var(\"HBBS_PORT\").ok().and_then(|p| p.parse().ok()).unwrap_or(21116);\nassert!(port >= 3, \"hbbs port must be >= 3, got {port}\");","typeGuard":"fn is_valid_port(p: i32) -> bool { p >= 3 && p <= 65535 }","tryCatchPattern":null,"preventionTips":["Never pass 0/1/2 as hbbs port; hbbs has no dynamic port allocation.","Validate port env/config values in deployment scripts before launching hbbs.","Pin the default (21116/21117) in docker-compose/systemd configs."],"tags":["cli","startup","port-validation","rust"],"backgroundTag":"invalid-cli-argument","analyzedSha":"a7736be5e40f85bfc141120dce587e836e5d4b80","analyzedAt":"2026-09-09T21:56:29.933Z","contentChangedAt":"2026-09-09T21:56:29.933Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}