summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2026-09-25 16:51:37 +0000
committerChristian Breunig <christian@breunig.cc>2026-09-26 09:46:20 +0200
commit744cb312dc3b0ed7326b1faee5c4db9e9a74a0df (patch)
tree1b7762498da7beefde53bd822fec8fa883f38053 /python
parentba43108f552fc3f6e7ef9ba8741c7612d948fb2c (diff)
downloadvyos-1x-744cb312dc3b0ed7326b1faee5c4db9e9a74a0df.tar.gz
vyos-1x-744cb312dc3b0ed7326b1faee5c4db9e9a74a0df.zip
vyos.utils: T8977: do not fail when a listening process vanishes mid-check
The list of listening sockets is a snapshot, and the owning process was looked up afterwards. A process exiting in between, or one belonging to another user when we do not run privileged, raised an exception that escaped and aborted the conf-mode script asking whether a port is taken. Neither case can be the service being looked for, so such a socket is skipped now.
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",