{"record":{"id":"08231baf2f38a80e","repo":"ansible/ansible","slug":"queryinformationjobobject-failed","errorCode":null,"errorMessage":"QueryInformationJobObject() failed","messagePattern":"QueryInformationJobObject\\(\\) failed","errorType":"exception","errorClass":"Win32Exception","httpStatus":null,"severity":"error","filePath":"lib/ansible/module_utils/csharp/Ansible._Async.cs","lineNumber":283,"sourceCode":"            {\n                throw new Win32Exception(\"IsProcessInJob() failed\");\n            }\n\n            if (!isInJob)\n            {\n                return true;\n            }\n\n            NativeHelpers.JOBOBJECT_BASIC_LIMIT_INFORMATION jobInfo = new NativeHelpers.JOBOBJECT_BASIC_LIMIT_INFORMATION();\n            bool jobRes = NativeMethods.QueryInformationJobObject(\n                IntPtr.Zero,\n                NativeHelpers.JobObjectBasicLimitInformation,\n                ref jobInfo,\n                Marshal.SizeOf<NativeHelpers.JOBOBJECT_BASIC_LIMIT_INFORMATION>(),\n                IntPtr.Zero);\n            if (!jobRes)\n            {\n                throw new Win32Exception(\"QueryInformationJobObject() failed\");\n            }\n\n            return (jobInfo.LimitFlags & NativeHelpers.JOB_OBJECT_LIMIT_BREAKAWAY_OK) != 0;\n        }\n\n        public static ProcessInformation CreateAsyncProcess(\n            string applicationName,\n            string commandLine,\n            SafeHandle stdin,\n            SafeHandle stdout,\n            SafeHandle stderr,\n            SafeHandle mutexHandle,\n            SafeHandle parentProcess,\n            StreamReader stdoutReader,\n            StreamReader stderrReader)\n        {\n            StringBuilder commandLineBuffer = new StringBuilder(commandLine);\n            int creationFlags = NativeHelpers.CREATE_NEW_CONSOLE |","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/ansible/ansible/blob/9cf16a4aca7898481c257f1e17ad28d0b67b1f85/lib/ansible/module_utils/csharp/Ansible._Async.cs#L265-L301","documentation":"Thrown by AsyncUtil.CanCreateBreakawayProcess when QueryInformationJobObject(JobObjectBasicLimitInformation) fails on the current job. After IsProcessInJob confirms the process is in a job, this query reads the job's limit flags to see whether JOB_OBJECT_LIMIT_BREAKAWAY_OK is set (i.e. children may escape the job). Failure means the flag query itself was rejected.","triggerScenarios":"Passing a NULL job handle (as done here) queries the assigned job, which fails with ERROR_ACCESS_DENIED if the job handle is not queryable by the caller; nested-job configurations on older Windows versions (pre-Win8 nested-job semantics); a job that was terminated concurrently.","commonSituations":"Ansible connections running inside scheduler/service job objects (SCM, Task Scheduler, CI agents) whose ACLs deny query rights to the module's token; Windows versions with partial nested-job support.","solutions":["Check the Win32ErrorCode: 5 suggests the containing job denies query access to your token.","Run the module/connection outside the restrictive job (e.g. interactive session instead of a hardened service) to confirm.","Ensure the async wrapper configuration does not require breakaway when the job forbids it (parentProcess-based spawning is the fallback path).","Report upstream with OS version if breakaway-eligible jobs still fail the query."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    ok = AsyncUtil.CanCreateBreakawayProcess();\n}\ncatch (Win32Exception ex) when (ex.Message.Contains(\"QueryInformationJobObject\"))\n{\n    // containing job denies the query (often access denied) or nested-job edge case;\n    // safest fallback: assume breakaway is NOT allowed and spawn under a parent process\n    ok = false;\n}","preventionTips":["When the connection runs under a scheduler/service job, prefer parent-process-based async spawning over breakaway.","Check job ACLs if you control the job object; grant query rights to the module's token.","Cache the result once per run instead of probing repeatedly."],"tags":["windows","job-object","win32","async","access-denied"],"backgroundTag":null,"analyzedSha":"9cf16a4aca7898481c257f1e17ad28d0b67b1f85","analyzedAt":"2026-08-15T00:15:47.100Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}