{"record":{"id":"cc928d8208a5627d","repo":"puppetlabs/puppet","slug":"setpriorityclass","errorCode":null,"errorMessage":"SetPriorityClass","messagePattern":"SetPriorityClass","errorType":"exception","errorClass":"SystemCallError","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/windows/monkey_patches/process.rb","lineNumber":195,"sourceCode":"    # * 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,\n        close_handles: true\n      }\n      @si_hash = nil\n      @procinfo = nil\n    end","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/windows/monkey_patches/process.rb#L177-L213","documentation":"In Process.setpriority, after OpenProcess succeeds, SetPriorityClass is invoked and a falsy result raises SystemCallError('SetPriorityClass', FFI.errno). Because the monkey patch forwards the value untouched to Windows, passing anything that is not a valid priority-class constant - most commonly Unix nice numbers like -5 or 10 - fails here (usually ERROR_INVALID_PARAMETER, 87).","triggerScenarios":"Process.setpriority(:process, pid, -5) or (…, 10) using Unix nice semantics; passing 0 or nil as the priority; a REALTIME_PRIORITY_CLASS request from a low-privilege token; a handle whose PROCESS_SET_INFORMATION access was stripped between open and set.","commonSituations":"Porting Unix scheduling scripts ('nice -n 5') to Windows via this API; config files carrying nice values fed verbatim to setpriority; JRuby/Windows CI differences where the same helper works on Linux.","solutions":["Pass Windows priority-class constants: Process::IDLE_PRIORITY_CLASS, :BELOW_NORMAL/:NORMAL/:ABOVE_NORMAL_PRIORITY_CLASS, :HIGH_PRIORITY_CLASS, :REALTIME_PRIORITY_CLASS","Translate Unix nice values explicitly (e.g. nice>0 -> BELOW_NORMAL, nice<0 -> ABOVE_NORMAL) before calling","Rescue SystemCallError and skip - never let priority tuning abort the main work"],"exampleFix":"// before\nProcess.setpriority(:process, pid, 10)  # Unix nice value -> SetPriorityClass fails\n\n// after\nProcess.setpriority(:process, pid, Process::BELOW_NORMAL_PRIORITY_CLASS)","handlingStrategy":"validation","validationCode":"VALID_PRIORITIES = [Process::IDLE_PRIORITY_CLASS, Process::BELOW_NORMAL_PRIORITY_CLASS,\n                    Process::NORMAL_PRIORITY_CLASS, Process::ABOVE_NORMAL_PRIORITY_CLASS,\n                    Process::HIGH_PRIORITY_CLASS, Process::REALTIME_PRIORITY_CLASS].freeze\nraise ArgumentError, \"not a Windows priority class: #{int_priority}\" unless VALID_PRIORITIES.include?(int_priority)\nProcess.setpriority(:process, pid, int_priority)","typeGuard":"def priority_class?(value)\n  [Process::IDLE_PRIORITY_CLASS, Process::BELOW_NORMAL_PRIORITY_CLASS,\n   Process::NORMAL_PRIORITY_CLASS, Process::ABOVE_NORMAL_PRIORITY_CLASS,\n   Process::HIGH_PRIORITY_CLASS, Process::REALTIME_PRIORITY_CLASS].include?(value)\nend","tryCatchPattern":"begin\n  Process.setpriority(:process, pid, int_priority)\nrescue SystemCallError => e\n  raise unless e.message.include?('SetPriorityClass')\n  warn \"skipping priority change for #{pid}: #{e.message}\"\nend","preventionTips":["Never feed Unix nice values (-20..20) to Windows setpriority","Translate nice semantics explicitly at your API boundary before calling","Avoid REALTIME_PRIORITY_CLASS except for trusted, dedicated processes"],"tags":["windows","process","priority","nice","ffi","puppet"],"backgroundTag":"process-priority-change-failed","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}