From 744cb312dc3b0ed7326b1faee5c4db9e9a74a0df Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Fri, 25 Sep 2026 16:51:37 +0000 Subject: 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. --- python/vyos/utils/network.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'python') 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", -- cgit v1.2.3