{"record":{"id":"945817267300354f","repo":"rustdesk/rustdesk","slug":"failed-to-read-server-process-uid","errorCode":null,"errorMessage":"Failed to read --server process uid","messagePattern":"Failed to read --server process uid","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ipc.rs","lineNumber":1399,"sourceCode":"    let mut server_uids = Vec::new();\n    for process in sys.processes().values() {\n        if process.pid() == current_pid {\n            continue;\n        }\n        if process.cmd().get(1).map_or(true, |arg| arg != \"--server\") {\n            continue;\n        }\n        let Ok(process_path) = std::fs::canonicalize(process.exe()) else {\n            continue;\n        };\n        if process_path != current_exe_path {\n            continue;\n        }\n        let Some(uid) = process.user_id().map(|uid| **uid as u32) else {\n            // Root CLI management commands need a stable matching `--server` target.\n            // If this key process races during enumeration, failing the command is clearer\n            // than silently skipping it; `--server` is not expected to exit frequently.\n            bail!(\"Failed to read --server process uid\");\n        };\n        server_uids.push(uid);\n    }\n    Ok(server_uids)\n}\n\n#[cfg(any(target_os = \"linux\", target_os = \"macos\"))]\nfn user_main_ipc_server_uid() -> ResultType<u32> {\n    let server_uids = running_server_uids_for_current_exe()?;\n    #[cfg(target_os = \"linux\")]\n    let prefer_root = crate::platform::linux::is_login_screen_wayland();\n    #[cfg(target_os = \"macos\")]\n    let prefer_root = false;\n    select_server_uid_for_user_main_ipc(&server_uids, active_uid(), prefer_root)\n}\n\npub async fn connect(ms_timeout: u64, postfix: &str) -> ResultType<ConnectionTmpl<ConnClient>> {\n    #[cfg(any(target_os = \"linux\", target_os = \"macos\"))]","sourceCodeStart":1381,"sourceCodeEnd":1417,"githubUrl":"https://github.com/rustdesk/rustdesk/blob/91c9fccbb0f7bfe5f11644d5fbdec9b23fa10540/src/ipc.rs#L1381-L1417","documentation":"While enumerating `--server` processes to find their uids, a process's user id could not be read (process.user_id() returned None). The code intentionally fails rather than silently skipping, because an unmatched key process would break stable uid-based target selection for root CLI commands.","triggerScenarios":"A `--server` process matched by exe path disappears or its metadata becomes unreadable mid-enumeration (race with process exit), or the OS denies uid access for that process.","commonSituations":"Service being restarted exactly while a management command runs; restricted /proc permissions in hardened environments (hidepid) or containers limiting process metadata access.","solutions":["Rerun the command — the race is transient","Check /proc permissions (hidepid mount option) if it reproduces","Ensure the RustDesk service is not being restarted concurrently","Run the enumeration with sufficient privileges to read process uids"],"exampleFix":"// before\nlet uids = running_server_uids_for_current_exe()?;\n// after\nlet uids = match running_server_uids_for_current_exe() {\n    Ok(u) => u,\n    Err(e) if e.to_string().contains(\"Failed to read --server process uid\") => {\n        std::thread::sleep(std::time::Duration::from_millis(200));\n        running_server_uids_for_current_exe()?\n    }\n    Err(e) => return Err(e),\n};","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match running_server_uids_for_current_exe() {\n    Ok(u) => u,\n    Err(e) if e.to_string().contains(\"uid\") => {\n        std::thread::sleep(Duration::from_millis(200));\n        running_server_uids_for_current_exe()?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Don't restart the service concurrently with management commands","Check /proc hidepid settings in hardened environments","Run with privileges sufficient to read process uids"],"tags":["process-lookup","race-condition","rustdesk","linux"],"backgroundTag":"resource-not-found","analyzedSha":"91c9fccbb0f7bfe5f11644d5fbdec9b23fa10540","analyzedAt":"2026-09-10T19:53:44.083Z","contentChangedAt":"2026-09-10T19:53:44.083Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}