{"record":{"id":"2946899cee54f707","repo":"windmill-labs/windmill","slug":"createjobobjectw-e","errorCode":null,"errorMessage":"CreateJobObjectW: {e}","messagePattern":"CreateJobObjectW: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/windmill-worker/src/common.rs","lineNumber":874,"sourceCode":"    Ok(())\n}\n\n/// Create a Windows Job Object and assign the process to it, optionally with\n/// KILL_ON_JOB_CLOSE (so the child tree is reaped when the worker drops the handle /\n/// dies) and/or a memory limit. Assigning post-spawn (rather than via process-wrap's\n/// suspend/resume JobObject wrap) keeps the dotnet-safe behavior that csharp relies on.\n#[cfg(windows)]\nfn assign_job_object(\n    pid: u32,\n    memory_limit: Option<usize>,\n    kill_on_close: bool,\n) -> Result<Win32JobHandle, std::io::Error> {\n    use windows::Win32::System::JobObjects::*;\n    use windows::Win32::System::Threading::{OpenProcess, PROCESS_SET_QUOTA, PROCESS_TERMINATE};\n\n    unsafe {\n        let job = CreateJobObjectW(None, None).map_err(|e| {\n            std::io::Error::new(std::io::ErrorKind::Other, format!(\"CreateJobObjectW: {e}\"))\n        })?;\n\n        let mut info = JOBOBJECT_EXTENDED_LIMIT_INFORMATION::default();\n        if kill_on_close {\n            info.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;\n        }\n        if let Some(memory_limit) = memory_limit {\n            info.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_JOB_MEMORY;\n            info.JobMemoryLimit = memory_limit;\n        }\n\n        SetInformationJobObject(\n            job,\n            JobObjectExtendedLimitInformation,\n            &info as *const _ as _,\n            std::mem::size_of::<JOBOBJECT_EXTENDED_LIMIT_INFORMATION>() as u32,\n        )\n        .map_err(|e| {","sourceCodeStart":856,"sourceCodeEnd":892,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/windmill-worker/src/common.rs#L856-L892","documentation":"assign_job_object creates a Windows Job object (CreateJobObjectW) to attach a child process so it can be killed and limited as a unit. If the kernel cannot create the job object, the error is wrapped with this message. Job object creation essentially only fails on resource/permission problems.","triggerScenarios":"start_child_process on Windows calling assign_job_object(pid, kill_on_close); CreateJobObjectW returns an error handle, e.g. when the system is out of handles/memory or object-name quota is exhausted.","commonSituations":"Resource exhaustion on a long-running Windows worker (handle leak), extremely restricted security contexts, or corrupted system state after many spawned jobs.","solutions":["Check the Win32 error code in the message; handle leaks are the usual cause — restart the worker process to release handles.","Verify the worker isn't leaking job objects (Win32JobHandle must be dropped/closed per job).","Retry the job after resource pressure drops.","Run in a normal user session rather than a stripped-down service context if policy blocks object creation."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Nothing callable to pre-validate; ensure the worker process has ample handle budget and is not near resource exhaustion before spawning children.","typeGuard":null,"tryCatchPattern":"match assign_job_object(pid, true) {\n    Err(e) if e.to_string().contains(\"CreateJobObjectW\") => {\n        // transient resource failure: surface to caller for job-level retry\n        Err(e)\n    }\n    other => other,\n}","preventionTips":["Restart workers periodically to release leaked handles","Ensure Win32JobHandle is always dropped so job objects close","Watch Windows handle counts on long-running workers"],"tags":["windows","win32","job-object","process"],"backgroundTag":"win32-api-call-failed","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}