Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[process_checker] Fix 'NoSuchProcess' exception in process_checker #5716

Merged
merged 1 commit into from
Oct 27, 2020

Conversation

bingwang-ms
Copy link
Contributor

- Why I did it
The psutil library used in process_checker create a cache for each process when calling process_iter. So, there is a small possibility that one process exists when calling process_iter, but not exists when calling cmdline, which will raise a NoSuchProcess exception.

File "/usr/bin/process_checker", line 57, in <module>
    main()
  File "/usr/bin/process_checker", line 53, in main
    check_process_existence(args.container_name, ' '.join(args.process_cmdline))
  File "/usr/bin/process_checker", line 31, in check_process_existence
    if ((' '.join(process.cmdline())).startswith(process_cmdline) and process.status() in ["running", "sleeping"]):
  File "/usr/local/lib/python2.7/dist-packages/psutil/__init__.py", line 694, in cmdline
    return self._proc.cmdline()
  File "/usr/local/lib/python2.7/dist-packages/psutil/_pslinux.py", line 1522, in wrapper
    raise NoSuchProcess(self.pid, self._name)
psutil.NoSuchProcess: psutil.NoSuchProcess process no longer exists (pid=7019)

This commit fix the issue.

Signed-off-by: bingwang [email protected]

- How I did it
Add a logic to catch NoSuchProcess and then ignore it.

- How to verify it
Write a sample test script which looply creates a processe that runs only for a few milliseconds. Meanwhile, process_checker is running looply.
Without this patch, the NoSuchProcess was found, and no exception was raises after the patch.

- Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006

- Description for the changelog

Fix NoSuchProcess exception in process_checker

- A picture of a cute animal (not mandatory but encouraged)

The psutil library used in process_checker create a cache for each
process when calling process_iter. So, there is some possibility that
one process exists when calling process_iter, but not exists when
calling cmdline, which will raise a NoSuchProcess exception. This commit
fix the issue.

Signed-off-by: bingwang <[email protected]>
@bingwang-ms bingwang-ms merged commit 36c52cc into sonic-net:master Oct 27, 2020
@keboliu
Copy link
Collaborator

keboliu commented Oct 27, 2020

also see this issue in our test, hope can be cherry-picked to 201911 soon.

@jleveque
Copy link
Contributor

@abdosi for visibility

abdosi pushed a commit that referenced this pull request Oct 30, 2020
The psutil library used in process_checker create a cache for each
process when calling process_iter. So, there is some possibility that
one process exists when calling process_iter, but not exists when
calling cmdline, which will raise a NoSuchProcess exception. This commit
fix the issue.

Signed-off-by: bingwang <[email protected]>
santhosh-kt pushed a commit to santhosh-kt/sonic-buildimage that referenced this pull request Feb 25, 2021
The psutil library used in process_checker create a cache for each
process when calling process_iter. So, there is some possibility that
one process exists when calling process_iter, but not exists when
calling cmdline, which will raise a NoSuchProcess exception. This commit
fix the issue.

Signed-off-by: bingwang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants