summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/vyos/utils/network.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/python/vyos/utils/network.py b/python/vyos/utils/network.py
index e4d98777b..e5fa398cf 100644
--- a/python/vyos/utils/network.py
+++ b/python/vyos/utils/network.py
@@ -450,6 +450,8 @@ def is_listen_port_bind_service(port: int, service: str, address: str = None) ->
"""
from psutil import net_connections as connections
from psutil import Process as process
+ from psutil import AccessDenied
+ from psutil import NoSuchProcess
from ipaddress import ip_address
has_address = bool(address)
@@ -470,7 +472,13 @@ def is_listen_port_bind_service(port: int, service: str, address: str = None) ->
if pid is None:
continue
- pid_name = process(pid).name()
+ # The socket table is a snapshot - the process behind it may be gone
+ # by now, or belong to another user. Neither can be our service.
+ try:
+ pid_name = process(pid).name()
+ except (NoSuchProcess, AccessDenied):
+ continue
+
pid_port = addr.port
# Ignore address check when service listening on "any address",