From 8224acc26762046a99ca7d345ed86729eda3673a Mon Sep 17 00:00:00 2001 From: derekpierre Date: Mon, 9 Sep 2024 14:40:22 -0400 Subject: [PATCH] Separate default timeout from max timeout. Ensure that environment variables are cast to integers. Increase max timeout (for now) for get_ursulas/bucket_sampling. --- porter/main.py | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/porter/main.py b/porter/main.py index 0cff118..068f7ba 100644 --- a/porter/main.py +++ b/porter/main.py @@ -64,13 +64,25 @@ class Porter(Learner): DEFAULT_PORT = 9155 - MAX_GET_URSULAS_TIMEOUT = os.getenv("PORTER_MAX_GET_URSULAS_TIMEOUT", default=30) - MAX_BUCKET_SAMPLING_TIMEOUT = os.getenv( - "PORTER_MAX_BUCKET_SAMPLING_TIMEOUT", default=30 + DEFAULT_GET_URSULAS_TIMEOUT = int( + os.getenv("PORTER_DEFAULT_GET_URSULAS_TIMEOUT", default=15) ) - MAX_DECRYPTION_TIMEOUT = os.getenv( - "PORTER_MAX_DECRYPTION_TIMEOUT", - default=ThresholdDecryptionClient.DEFAULT_DECRYPTION_TIMEOUT, + MAX_GET_URSULAS_TIMEOUT = int( + os.getenv("PORTER_MAX_GET_URSULAS_TIMEOUT", default=30) + ) + + DEFAULT_BUCKET_SAMPLING_TIMEOUT = int( + os.getenv("PORTER_DEFAULT_GET_URSULAS_TIMEOUT", default=25) + ) + MAX_BUCKET_SAMPLING_TIMEOUT = int( + os.getenv("PORTER_MAX_BUCKET_SAMPLING_TIMEOUT", default=45) + ) + + MAX_DECRYPTION_TIMEOUT = int( + os.getenv( + "PORTER_MAX_DECRYPTION_TIMEOUT", + default=ThresholdDecryptionClient.DEFAULT_DECRYPTION_TIMEOUT, + ) ) _interface_class = PorterInterface @@ -182,7 +194,9 @@ def get_ursulas( min_version: Optional[str] = None, ) -> List[UrsulaInfo]: timeout = self._configure_timeout( - "sampling", timeout, self.MAX_GET_URSULAS_TIMEOUT + "sampling", + timeout or self.DEFAULT_GET_URSULAS_TIMEOUT, + self.MAX_GET_URSULAS_TIMEOUT, ) duration = duration or 0 parse_min_version = parse(min_version) if min_version else None @@ -328,7 +342,9 @@ def bucket_sampling( min_version: Optional[str] = None, ) -> Tuple[List[ChecksumAddress], int]: timeout = self._configure_timeout( - "bucket_sampling", timeout, self.MAX_BUCKET_SAMPLING_TIMEOUT + "bucket_sampling", + timeout or self.DEFAULT_BUCKET_SAMPLING_TIMEOUT, + self.MAX_BUCKET_SAMPLING_TIMEOUT, ) duration = duration or 0 parse_min_version = parse(min_version) if min_version else None @@ -473,7 +489,7 @@ def make_sure_ursula_is_online(ursula_address) -> ChecksumAddress: ) # TODO determine "best" value here without env var or parameterize - stagger_timeout = os.getenv("PORTER_STAGGER_TIMEOUT", default=1) + stagger_timeout = int(os.getenv("PORTER_STAGGER_TIMEOUT", default=1)) worker_pool = WorkerPool( worker=make_sure_ursula_is_online,