Skip to content

Commit

Permalink
Fix #1512 proc connections() fails with EOPNOTSUPP
Browse files Browse the repository at this point in the history
...on macOS. Just occurs sometimes for 1 socket only. Ignore the error
and continue.

Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
  • Loading branch information
giampaolo committed Dec 29, 2020
1 parent 8687a11 commit d8a8a85
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ XXXX-XX-XX

- 1456_: [macOS] psutil.cpu_freq()'s min and max are set to 0 if can't be
determined (instead of crashing).
- 1512_: [macOS] sometimes Process.connections() will crash with EOPNOTSUPP
for one connection; this is now ignored.
- 1892_: [macOS] psutil.cpu_freq() broken on Apple M1.

5.8.0
Expand Down
16 changes: 10 additions & 6 deletions psutil/_psutil_osx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1027,9 +1027,18 @@ psutil_proc_connections(PyObject *self, PyObject *args) {
PROC_PIDFDSOCKETINFO, &si, sizeof(si));

// --- errors checking
if ((nb <= 0) || (nb < sizeof(si))) {
if ((nb <= 0) || (nb < sizeof(si)) || (errno != 0)) {
if (errno == EBADF) {
// let's assume socket has been closed
psutil_debug("proc_pidfdinfo(PROC_PIDFDSOCKETINFO) -> "
"EBADF (ignored)");
continue;
}
else if (errno == EOPNOTSUPP) {
// may happen sometimes, see:
// https://github.com/giampaolo/psutil/issues/1512
psutil_debug("proc_pidfdinfo(PROC_PIDFDSOCKETINFO) -> "
"EOPNOTSUPP (ignored)");
continue;
}
else {
Expand Down Expand Up @@ -1063,11 +1072,6 @@ psutil_proc_connections(PyObject *self, PyObject *args) {
if (inseq == 0)
continue;

if (errno != 0) {
PyErr_SetFromErrno(PyExc_OSError);
goto error;
}

if ((family == AF_INET) || (family == AF_INET6)) {
if (family == AF_INET) {
inet_ntop(AF_INET,
Expand Down

0 comments on commit d8a8a85

Please sign in to comment.