I wrote myself a simple script that lists open ports, and noticed that a solid 7 out of 10 times I run it, it will lead to deadlocking both qbittorrent, tailscaled and syncthing, those will stay with 200-400% CPU usage and require SIGKILL to get rid of them. I can run lsof sudo lsof -i -P -n and it does not seems to trigger the probelm. Linux seems unaffected, must be something MacOS API specific.
#!/usr/bin/env python3
import psutil
for entry in psutil.net_connections(kind='inet'):
if entry.status == 'LISTEN':
proc = psutil.Process(entry.pid).as_dict()
username = proc['username']
name = proc['name']
cmdline = proc['cmdline']
cmdline = list(filter(None, cmdline))
bind_ip = entry.laddr.ip
bind_port = entry.laddr.port
print(
f"{username} {name} {bind_ip}:{bind_port}"
)
After some more testing I think it might be related to the as_dict() method that lookup the individual connections of each process and this is how it triggers.
Summary
Description
I wrote myself a simple script that lists open ports, and noticed that a solid 7 out of 10 times I run it, it will lead to deadlocking both qbittorrent, tailscaled and syncthing, those will stay with 200-400% CPU usage and require SIGKILL to get rid of them. I can run lsof
sudo lsof -i -P -n
and it does not seems to trigger the probelm. Linux seems unaffected, must be something MacOS API specific.