{"record":{"id":"46915d226f8f9b17","repo":"clash-verge-rev/clash-verge-rev","slug":"failed-to-configure-job-object-for-sidecar-pid-pi","errorCode":null,"errorMessage":"failed to configure Job Object for sidecar PID {pid}: {job_error:#}; failed to terminate child: {kill_error:#}","messagePattern":"failed to configure Job Object for sidecar PID (.+?): (.+?); failed to terminate child: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/src/core/manager/state.rs","lineNumber":157,"sourceCode":"            crate::core::owner_identity::current_user_pipe_sddl()?,\n        );\n        let (mut rx, child) = command.spawn().map_err(|error| {\n            anyhow::anyhow!(\n                \"failed to start sidecar core {clash_core:?} with config {} and data directory {}: {error:#}\",\n                config_file.display(),\n                config_dir.display()\n            )\n        })?;\n        #[cfg(target_os = \"windows\")]\n        let job = {\n            match create_and_assign_sidecar_job(child.pid()) {\n                Ok(job) => job,\n                Err(job_error) => {\n                    let pid = child.pid();\n\n                    let error = match child.kill() {\n                        Ok(()) => job_error,\n                        Err(kill_error) => anyhow::anyhow!(\n                            \"failed to configure Job Object for sidecar PID {pid}: \\\n                            {job_error:#}; failed to terminate child: {kill_error:#}\"\n                        ),\n                    };\n\n                    logging!(error, Type::Core, \"Failed to start sidecar: {error:#}\");\n                    return Err(error);\n                }\n            }\n        };\n\n        #[cfg(unix)]\n        unsafe {\n            tauri_plugin_clash_verge_sysinfo::libc::umask(previous_mask)\n        };\n\n        let pid = child.pid();\n        logging!(trace, Type::Core, \"Sidecar started with PID: {}\", pid);","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/clash-verge-rev/clash-verge-rev/blob/5cad0f2799e74b1105e133bcfc2a45f5c1370ef1/src-tauri/src/core/manager/state.rs#L139-L175","documentation":"Windows-only. After spawn succeeds, create_and_assign_sidecar_job(child.pid()) is called to put the sidecar into a Job Object with KILL_ON_JOB_CLOSE so it dies with the app. If Job Object assignment fails, the code attempts to clean up by child.kill(); if that kill ALSO fails, the two errors are combined into this bail and the readiness flow aborts. It is a compound failure: cannot manage the process AND cannot terminate it.","triggerScenarios":"create_and_assign_sidecar_job returned an error (e.g. OpenProcess/AssignProcessToJobObject failed — permission denied, job nesting limits on older Windows, process already in a conflicting job), and immediately afterward child.kill() also returned an error (process already exited, handle invalid, access denied).","commonSituations":"Running the app under a parent process that already places children in a Job Object that disallows nested job assignment; antivirus injecting into the child so kill fails; the sidecar exited on its own in the microsecond between assign-attempt and kill so the handle is no longer valid.","solutions":["Read job_error first — most often OpenProcess/AssignProcessToJobObject permission or nesting; run the app outside of job-constrained hosts (e.g. some CI/terminal job wrappers).","Confirm the app (and its service, if elevated) has the necessary process rights to manage the sidecar PID.","If reproducing in CI, disable nested-job restrictions or run the app directly rather than under a job-bearing shell.","Check whether the sidecar crashed instantly — if so, fix the underlying crash and the compound error disappears."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match core_manager.start_core_by_sidecar().await {\n    Ok(_) => Ok(()),\n    Err(e) if e.to_string().contains(\"failed to configure Job Object\") => {\n        // surface the windows job-assignment error; advise running outside job-constrained hosts\n        Err(e)\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Do not launch the app under a parent that places children in a non-nested Job Object.","Grant the app/service the process rights needed to manage the sidecar PID.","Investigate job_error first; the kill_error is downstream."],"tags":["windows","job-object","sidecar","cleanup-failure"],"analyzedSha":"5cad0f2799e74b1105e133bcfc2a45f5c1370ef1","analyzedAt":"2026-08-12T03:25:57.699Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}