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

[MacOS] psutil.net_connections() Operation not supported on socket #1512

Closed
rtkaratekid opened this issue May 20, 2019 · 2 comments
Closed
Assignees

Comments

@rtkaratekid
Copy link

Platform

  • MacOS X - Mojave
  • psutil version - 5.6.1

Bug description
Running psutil.net_connections() a few thousand times while monitoring the machine leads to this error message. It looks like there is an issue in the _psosx.py file that is trying to run cext.proc_connections() on a socket

traceback message (

  File "macos_agent.py", line 86, in ip_receive
    connections = psutil.net_connections()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/psutil/__init__.py", line 2248, in net_connections
    return _psplatform.net_connections(kind)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/psutil/_psosx.py", line 252, in net_connections
    cons = Process(pid).connections(kind)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/psutil/_psosx.py", line 339, in wrapper
    return fun(self, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/psutil/_psosx.py", line 528, in connections
    rawlist = cext.proc_connections(self.pid, families, types)
OSError: [Errno 102] Operation not supported on socket

)
connections = psutil.net_connections()

Test results

# No failures
@giampaolo
Copy link
Owner

Hard to tell where this comes from as the C function implementing it is quite big. My best guess is that it originates either from here:

psutil/psutil/_psutil_osx.c

Lines 1106 to 1108 in b31f3bf

pidinfo_result = psutil_proc_pidinfo(pid, PROC_PIDLISTFDS, 0, NULL, 0);
if (pidinfo_result <= 0)
goto error;

...or here:

psutil/psutil/_psutil_osx.c

Lines 1116 to 1119 in b31f3bf

pidinfo_result = psutil_proc_pidinfo(
pid, PROC_PIDLISTFDS, 0, fds_pointer, pidinfo_result);
if (pidinfo_result <= 0)
goto error;

You should git clone psutil repo, add a printf() statement, recompile (make install) and try it yourself though 'cause I can't reproduce it.

@giampaolo giampaolo added bug osx and removed bug labels May 28, 2019
@electrozen
Copy link

I confirm the behavior still exists with ps_util 5.7.0 and macOS 10.15.3 when looping a thousand times over this:
for proc in psutil.process_iter(): info = proc.as_dict(attrs=['pid', 'name', 'username', 'connections'])

Operation not supported on socket

@giampaolo giampaolo added macos and removed osx labels Nov 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants