[PATCH] Add timeout to _poll_loop function to avoid infinite looping

Jiri Prochazka jprochaz at redhat.com
Mon Jun 29 13:35:56 UTC 2015


When Slave is using NetworkManager, polling is used to activate DBus connection.
This may result in infinite loop (eg. when device is not in LOWER_UP state, but is in UP state).
This patch adds timeout control in _poll_loop method, timeout value is set to 10s.

Signed-off-by: Jiri Prochazka <jprochaz at redhat.com>
---
 lnst/Slave/NmConfigDevice.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lnst/Slave/NmConfigDevice.py b/lnst/Slave/NmConfigDevice.py
index 8e2f1dd..82e0cb8 100644
--- a/lnst/Slave/NmConfigDevice.py
+++ b/lnst/Slave/NmConfigDevice.py
@@ -153,10 +153,14 @@ class NmConfigDeviceGeneric(object):
             self._loop.quit()
 
     def _poll_loop(self, func, expected_val, *args):
-        while True:
+        timer = 0
+        while timer < 10:
             if func(*args) == expected_val:
                 break
             time.sleep(1)
+            timer += 1
+        msg = "Timed out during NetworkManager polling."
+        raise Exception(msg)
 
     def _convert_hwaddr(self, dev_config):
         if "hwaddr" in dev_config:
-- 
2.4.3



More information about the LNST-developers mailing list