{"record":{"id":"d99a22e675f1c88b","repo":"puppetlabs/puppet","slug":"openprocess","errorCode":null,"errorMessage":"OpenProcess","messagePattern":"OpenProcess","errorType":"exception","errorClass":"SystemCallError","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/windows/monkey_patches/process.rb","lineNumber":190,"sourceCode":"    # Possible +int_priority+ values are:\n    #\n    # * Process::NORMAL_PRIORITY_CLASS\n    # * Process::IDLE_PRIORITY_CLASS\n    # * Process::HIGH_PRIORITY_CLASS\n    # * Process::REALTIME_PRIORITY_CLASS\n    # * Process::BELOW_NORMAL_PRIORITY_CLASS\n    # * Process::ABOVE_NORMAL_PRIORITY_CLASS\n\n    def setpriority(kind, int, int_priority)\n      raise TypeError unless kind.is_a?(Integer)\n      raise TypeError unless int.is_a?(Integer)\n      raise TypeError unless int_priority.is_a?(Integer)\n\n      int = Process.pid if int == 0\n      handle = OpenProcess(PROCESS_SET_INFORMATION, 0, int)\n\n      if handle == 0\n        raise SystemCallError, FFI.errno, \"OpenProcess\"\n      end\n\n      begin\n        result = SetPriorityClass(handle, int_priority)\n        raise SystemCallError, FFI.errno, \"SetPriorityClass\" unless result\n      ensure\n        FFI::WIN32.CloseHandle(handle)\n      end\n\n      0\n    end\n\n    private\n\n    def initialize_defaults\n      @hash = {\n        app_name: nil,\n        creation_flags: 0,","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/windows/monkey_patches/process.rb#L172-L208","documentation":"The win32-process monkey patch Process.setpriority opens the target PID with OpenProcess(PROCESS_SET_INFORMATION) and raises SystemCallError (message 'OpenProcess', errno from FFI.errno) when the handle comes back NULL. It means Windows refused to give you a handle: the PID no longer exists (ERROR_INVALID_PARAMETER, 87) or you lack rights to a process of higher integrity (ERROR_ACCESS_DENIED, 5).","triggerScenarios":"Process.setpriority(:process, pid, priority_class) where pid already exited (87); targeting a service/elevated process from a non-elevated agent (5); passing 0 (rewritten to Process.pid, which succeeds) vs a stale PID captured earlier; PID reuse pointing at a protected system process.","commonSituations":"Puppet or daemon scripts lowering priority of child processes that finish quickly; non-admin agents adjusting priority of processes started by SYSTEM; monitoring loops caching PIDs across restarts.","solutions":["Treat 87 as 'process gone' - verify the PID is alive immediately before calling and skip dead ones","For 5, run the caller elevated or at the same integrity level as the target process","Rescue SystemCallError and degrade gracefully (priority is an optimization, rarely fatal)","Re-resolve PIDs each iteration instead of caching them"],"exampleFix":"// before\nProcess.setpriority(:process, cached_pid, Process::BELOW_NORMAL_PRIORITY_CLASS)  # dead pid -> 87\n\n// after\nbegin\n  Process.setpriority(:process, pid, Process::BELOW_NORMAL_PRIORITY_CLASS)\nrescue SystemCallError => e\n  warn \"priority change skipped for pid #{pid}: #{e.message}\" # 87=exited, 5=access denied\nend","handlingStrategy":"try-catch","validationCode":"raise ArgumentError, 'pid must be a positive Integer' unless int.is_a?(Integer) && int.positive?\n# existence still cannot be guaranteed without a race - keep the rescue below","typeGuard":null,"tryCatchPattern":"begin\n  Process.setpriority(:process, pid, priority_class)\nrescue SystemCallError => e\n  # 87 = process exited, 5 = access denied (elevated target)\n  warn \"setpriority skipped for pid #{pid}: #{e.message}\"\nend","preventionTips":["Verify the PID is alive immediately before the call and tolerate it dying anyway","Expect 87 for short-lived children - skip rather than fail","Run at the same elevation as the target process when adjusting priorities"],"tags":["windows","process","priority","openprocess","ffi","puppet"],"backgroundTag":"win32-openprocess-failed","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}