Skip to content

im_mad/lib/process_list.rb: guard against cpu_j == 0 and negative delta when process exits #8195

Closed

Description

@trukhinyuri

Description
In ProcessList.cpu_info (src/im_mad/remotes/lib/process_list.rb, lines 77-85):

        cpu_j = jiffies - j_ini

        cpu = {}

        pids.each do |pid|
            cpu[pid] = (proc_jiffies(pid) - cpu_ini[pid]) / cpu_j
            cpu[pid] = (cpu[pid] * multiplier).round(2)
        end

Two edge cases occur during host/VM monitoring:

  1. If cpu_j <= 0 (for example if /proc/stat fails or returns identical ticks), (proc_jiffies(pid) - cpu_ini[pid]) / cpu_j produces NaN or Infinity, and .round(2) / .to_i raises FloatDomainError.
  2. If a monitored process terminates during sleep AVERAGE_SECS, proc_jiffies(pid) rescues Errno::ENOENT and returns 0, making proc_jiffies(pid) - cpu_ini[pid] negative and reporting negative CPU usage.

To Reproduce

  1. Call ProcessList.cpu_info when a process exits during sleep AVERAGE_SECS or when cpu_j == 0.
  2. Observe negative CPU percentage or FloatDomainError: NaN.

Expected behavior
ProcessList.cpu_info should check cpu_j > 0 and j_end >= cpu_ini[pid], setting cpu[pid] = 0.0 otherwise.

Details

  • Affected Component: IM monitoring library (src/im_mad/remotes/lib/process_list.rb)
  • Version: master and 7.0.1

Progress Status

  • Code committed
  • Testing - QA
  • Documentation (Release notes - resolved issues, compatibility, known issues)

Activity

  1. added a commit that references this issue on Nov 2, 2026
  2. added this to the Release 7.4.2 milestone on Nov 2, 2026
  3. added theissue type on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions