The util function used in some conf_mode scripts to check port availability (`check_port_availability`) can return False due to error EADDRNOTAVAIL: "nonexistent interface', as a result of a race condition with the interface becoming available: noticed address set by dhcp and https virtual host listen-address set. Though not limited to the following case, it was more common with https included in scripts run by the config daemon (T5292); that is likely due to the decreased overhead of interpreter startup increasing likelihood of a race.
One obvious fix is to return False only on EADDRINUSE, which is the intention of the check:
```
diff --git a/python/vyos/util.py b/python/vyos/util.py
index 61ce59324..e62f9d5cf 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -1063,9 +1063,13 @@ def check_port_availability(ipaddress, port, protocol):
if protocol == 'udp':
server = UDPServer((ipaddress, port), None, bind_and_activate=True)
server.server_close()
- return True
- except:
- return False
+ except Exception as e:
+ # errno.h:
+ #define EADDRINUSE 98 /* Address already in use */
+ if e.errno == 98:
+ return False
+
+ return True
def install_into_config(conf, config_paths, override_prompt=True):
# Allows op-mode scripts to install values if called from an active config session
--
```