[PATCH] Add timeout to _poll_loop function to avoid infinite looping
Ondrej Lichtner
olichtne at redhat.com
Mon Jun 29 14:19:05 UTC 2015
On Mon, Jun 29, 2015 at 04:06:40PM +0200, Jiri Prochazka wrote:
> 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 | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/lnst/Slave/NmConfigDevice.py b/lnst/Slave/NmConfigDevice.py
> index 8e2f1dd..3da54f1 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:
^^^^
This should be a parameter of the function not just a random constant...
And there should be a defult value constant at the start of the file
where other NM related constants are defined.
> if func(*args) == expected_val:
> - break
> + return
> 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
>
> _______________________________________________
> LNST-developers mailing list
> LNST-developers at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/lnst-developers
More information about the LNST-developers
mailing list