Page MenuHomeVyOS Platform

verification of port availability can return false negative on boot
Closed, ResolvedPublicBUG

Description

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 with the host address set by dhcp and https virtual host listen-address explicitly set. Though not limited to the following case, it was more common when the https config_mode script was 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
-- 

Details

Version
vyos-1.4
Is it a breaking change?
Unspecified (possibly destroys the router)
Issue type
Bug (incorrect behavior)

Event Timeline

jestabro changed the task status from Open to In progress.
jestabro triaged this task as High priority.
jestabro created this object in space S1 VyOS Public.
jestabro moved this task from Open to Finished on the VyOS 1.4 Sagitta board.