From d8a8a85997bd59b720dd7456ebc1835d0e9dcd9b Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Tue, 29 Dec 2020 02:08:48 +0100 Subject: [PATCH] Fix #1512 proc connections() fails with EOPNOTSUPP ...on macOS. Just occurs sometimes for 1 socket only. Ignore the error and continue. Signed-off-by: Giampaolo Rodola --- HISTORY.rst | 2 ++ psutil/_psutil_osx.c | 16 ++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 9f5281f97..a33f5eb30 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -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 diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c index 62a95774c..5a77de143 100644 --- a/psutil/_psutil_osx.c +++ b/psutil/_psutil_osx.c @@ -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 { @@ -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,