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

[OpenBSD] Process num_fds() and open_files() may raise NSP for PID 0 #2460

Merged
merged 9 commits into from
Oct 14, 2024

Conversation

giampaolo
Copy link
Owner

@giampaolo giampaolo commented Oct 14, 2024

This is weird, because of all the sudden the tests below started failing. This is despite PID 0 exists. The syscall failing with ESRCH is kinfo_getfile:

kinfo_getfile(pid_t pid, int* cnt) {

We therefore return "null" fallback values instead of raising NoSuchProcess.

=================================== FAILURES ===================================
___________________________ TestProcess.test_as_dict ___________________________
psutil/_psbsd.py:604: in wrapper
    return fun(self, *args, **kwargs)
psutil/_psbsd.py:914: in open_files
    rawlist = cext.proc_open_files(self.pid)
E   ProcessLookupError: [Errno 3] No such process (originated from sysctl(kinfo_file) (1/2))

During handling of the above exception, another exception occurred:
psutil/tests/test_process.py:1309: in test_as_dict
    d = p.as_dict()
psutil/__init__.py:558: in as_dict
    ret = meth()
psutil/__init__.py:1199: in open_files
    return self._proc.open_files()
psutil/_psbsd.py:609: in wrapper
    raise NoSuchProcess(self.pid, self._name)
E   psutil.NoSuchProcess: process no longer exists (pid=0)
____________________________ TestProcess.test_pid_0 ____________________________
psutil/_psbsd.py:604: in wrapper
    return fun(self, *args, **kwargs)
psutil/_psbsd.py:914: in open_files
    rawlist = cext.proc_open_files(self.pid)
E   ProcessLookupError: [Errno 3] No such process (originated from sysctl(kinfo_file) (1/2))

During handling of the above exception, another exception occurred:
psutil/tests/test_process.py:1513: in test_pid_0
    ret = fun()
psutil/__init__.py:1199: in open_files
    return self._proc.open_files()
psutil/_psbsd.py:609: in wrapper
    raise NoSuchProcess(self.pid, self._name)
E   psutil.NoSuchProcess: process no longer exists (pid=0)
________________________ TestFetchAllProcesses.test_all ________________________
psutil/_psbsd.py:604: in wrapper
    return fun(self, *args, **kwargs)
psutil/_psbsd.py:914: in open_files
    rawlist = cext.proc_open_files(self.pid)
E   ProcessLookupError: [Errno 3] No such process (originated from sysctl(kinfo_file) (1/2))

During handling of the above exception, another exception occurred:
psutil/tests/test_process_all.py:93: in proc_info
    info[fun_name] = fun()
psutil/__init__.py:1199: in open_files
    return self._proc.open_files()
psutil/_psbsd.py:609: in wrapper
    raise NoSuchProcess(self.pid, self._name)
E   psutil.NoSuchProcess: process no longer exists (pid=0, name='swapper')

During handling of the above exception, another exception occurred:
psutil/tests/test_process_all.py:135: in test_all
    for info in self.iter_proc_info():
psutil/tests/test_process_all.py:130: in iter_proc_info
    ls.append(proc_info(pid))
psutil/tests/test_process_all.py:95: in proc_info
    check_exception(exc, proc, name, ppid)
psutil/tests/test_process_all.py:65: in check_exception
    tcase.assertProcessGone(proc)
psutil/tests/__init__.py:1069: in assertProcessGone
    self.assertPidGone(proc.pid)
psutil/tests/__init__.py:1057: in assertPidGone
    with pytest.raises(psutil.NoSuchProcess) as cm:
E   Failed: DID NOT RAISE <class 'psutil.NoSuchProcess'>

@giampaolo giampaolo merged commit f65fe44 into master Oct 14, 2024
28 of 29 checks passed
@giampaolo giampaolo deleted the fix-openbsd branch October 14, 2024 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant