{"record":{"id":"f161fac69c738413","repo":"abhigyanpatwari/GitNexus","slug":"createjobobjectw-failed","errorCode":null,"errorMessage":"CreateJobObjectW failed","messagePattern":"CreateJobObjectW failed","errorType":"exception","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"eval/workflow_bench/process_control.py","lineNumber":255,"sourceCode":"        kernel32.AssignProcessToJobObject.restype = wintypes.BOOL\n        kernel32.TerminateJobObject.argtypes = [wintypes.HANDLE, wintypes.UINT]\n        kernel32.TerminateJobObject.restype = wintypes.BOOL\n        kernel32.QueryInformationJobObject.argtypes = [\n            wintypes.HANDLE,\n            ctypes.c_int,\n            ctypes.c_void_p,\n            wintypes.DWORD,\n            ctypes.POINTER(wintypes.DWORD),\n        ]\n        kernel32.QueryInformationJobObject.restype = wintypes.BOOL\n        kernel32.CloseHandle.argtypes = [wintypes.HANDLE]\n        kernel32.CloseHandle.restype = wintypes.BOOL\n        ntdll.NtResumeProcess.argtypes = [wintypes.HANDLE]\n        ntdll.NtResumeProcess.restype = wintypes.LONG\n\n        handle = kernel32.CreateJobObjectW(None, None)\n        if not handle:\n            raise OSError(ctypes.get_last_error(), \"CreateJobObjectW failed\")\n        self._kernel32 = kernel32\n        self._handle = handle\n        ownership_slot[-1] = (process, self, None)\n        try:\n            limits = JOBOBJECT_EXTENDED_LIMIT_INFORMATION()\n            limits.BasicLimitInformation.LimitFlags = 0x00002000  # KILL_ON_JOB_CLOSE\n            if not kernel32.SetInformationJobObject(handle, 9, ctypes.byref(limits), ctypes.sizeof(limits)):\n                raise OSError(ctypes.get_last_error(), \"SetInformationJobObject failed\")\n            process_handle = wintypes.HANDLE(int(process._handle))  # type: ignore[attr-defined]\n            if not kernel32.AssignProcessToJobObject(handle, process_handle):\n                raise OSError(ctypes.get_last_error(), \"AssignProcessToJobObject failed\")\n            status = int(ntdll.NtResumeProcess(process_handle))\n            if status != 0:\n                raise OSError(status, \"NtResumeProcess failed\")\n        except BaseException:\n            # The child is still suspended when assignment fails. Kill it\n            # before releasing any handle; never retry with job breakaway.\n            process.kill()","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/eval/workflow_bench/process_control.py#L237-L273","documentation":"_WindowsJob.__init__ calls kernel32.CreateJobObjectW(None, None); if it returns a NULL handle the harness raises OSError(get_last_error(), ...). This is a Win32 resource-allocation failure during process spawning for ownership tracking — it can only occur on Windows (os.name == 'nt').","triggerScenarios":"Hit on Windows only, in _spawn -> _WindowsJob(process, ownership_slot) when CreateJobObjectW returns 0. Commonly caused by exhausting the process handle table, very low commit / nonpaged pool, or running under a sandbox that blocks job creation.","commonSituations":"Long-running benchmark loops leak handles and exhaust the per-process handle quota; AV/EDR blocks job-object creation; running under Wine/ReactOS where the call is unimplemented; severe memory pressure during a fan-out of subprocesses.","solutions":["Check the Win32 error code in the OSError (errno attr) — e.g. ERROR_NOT_ENOUGH_MEMORY (8) or ERROR_ACCESS_DENIED (5) — for the specific cause.","Reduce concurrency / leak less: ensure every prior _WindowsJob is close()'d before spawning more.","Disable any AV/EDR rule that blocks Job Object creation, or run the benchmark in an environment that permits it.","Switch the run to a POSIX host (Linux) where the job path is not used."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"# Pre-flight on Windows: check the handle table is not already saturated.\nimport sys\nif sys.platform == 'win32':\n    import psutil  # optional\n    p = psutil.Process()\n    if p.num_handles() > 10_000_000:  # near the per-process ceiling\n        raise RuntimeError('handle table saturated; close resources before spawning jobs')","typeGuard":null,"tryCatchPattern":"import sys\nif sys.platform == 'win32':\n    try:\n        result = run_managed(cmd, timeout=60)\n    except OSError as exc:\n        if exc.winerror in (8, 1450):  # ERROR_NOT_ENOUGH_MEMORY / quota lack\n            log.error('job creation failed on resource exhaustion: %s', exc)\n            # back off and retry once, or fall back to a POSIX host\n        raise","preventionTips":["Always close _WindowsJob instances explicitly via close() or context.","Run the benchmark on a Windows host with adequate commit / nonpaged pool budget.","Prefer Linux for high-throughput fan-out; the Windows path is for parity, not performance."],"tags":["windows","win32","job-object","ctypes","handle-leak","process-control"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}