From a4241fc2745cb37d721961aa3e4b7de6758f1e7f Mon Sep 17 00:00:00 2001 From: abuabraham-ttd Date: Wed, 11 Dec 2024 08:46:25 -0800 Subject: [PATCH] Loop every sec for 10sec for confg server to be up --- scripts/aws/ec2.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/aws/ec2.py b/scripts/aws/ec2.py index f0cb59356..455541aef 100644 --- a/scripts/aws/ec2.py +++ b/scripts/aws/ec2.py @@ -145,17 +145,25 @@ def _setup_auxiliaries(self) -> None: self.__setup_vsockproxy(log_level) self.__run_config_server() self.__run_socks_proxy() - time.sleep(5) #TODO: Change to while loop if required. def _validate_auxiliaries(self) -> None: """Validates connection to flask server direct and through socks proxy.""" proxy = "socks5://127.0.0.1:3306" config_url = "http://127.0.0.1:27015/getConfig" try: - response = requests.get(config_url) + for attempt in range(10): + try: + response = requests.get(config_url) + print("Config server is reachable") + break + except requests.exceptions.ConnectionError as e: + print(f"Connecting to config server, attempt {attempt + 1} failed with ConnectionError: {e}") + time.sleep(1) + else: + raise RuntimeError(f"Config server unreachable") response.raise_for_status() except requests.RequestException as e: - raise RuntimeError(f"Config server unreachable: {e}") + raise RuntimeError(f"Failed to get config from config server: {e}") proxies = {"http": proxy, "https": proxy} try: response = requests.get(config_url, proxies=proxies)