From 6a1a004eb2b1966101dc08b9f84e2473eb03e563 Mon Sep 17 00:00:00 2001 From: Fredrik Wrede Date: Tue, 3 Oct 2023 14:16:55 +0000 Subject: [PATCH] add max tries to avoid endless loop --- fedn/fedn/network/controller/controlbase.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fedn/fedn/network/controller/controlbase.py b/fedn/fedn/network/controller/controlbase.py index f033b0b29..e38d31e38 100644 --- a/fedn/fedn/network/controller/controlbase.py +++ b/fedn/fedn/network/controller/controlbase.py @@ -10,6 +10,9 @@ from fedn.network.combiner.interfaces import CombinerUnavailableError from fedn.network.state import ReducerState +# Maximum number of tries to connect to statestore and retrieve storage configuration +MAX_TRIES_BACKEND = os.getenv('MAX_TRIES_BACKEND', 10) + class UnsupportedStorageBackend(Exception): pass @@ -42,12 +45,18 @@ def __init__(self, statestore): try: not_ready = True + tries = 0 while not_ready: storage_config = self.statestore.get_storage_backend() if storage_config: not_ready = False else: + print( + "REDUCER CONTROL: Storage backend not configured, waiting...", flush=True) sleep(5) + tries += 1 + if tries > MAX_TRIES_BACKEND: + raise Exception except Exception: print( "REDUCER CONTROL: Failed to retrive storage configuration, exiting.", flush=True)