diff --git a/dkg/providers/node/async_node_http.py b/dkg/providers/node/async_node_http.py index 7a3a1f4..7cb17c2 100644 --- a/dkg/providers/node/async_node_http.py +++ b/dkg/providers/node/async_node_http.py @@ -30,8 +30,10 @@ def __init__( endpoint_uri: URI | str, api_version: str = "v1", auth_token: str | None = None, + timeout: int = 60, # timeout in seconds ): super().__init__(endpoint_uri, api_version, auth_token) + self.timeout = timeout async def make_request( self, @@ -42,7 +44,9 @@ async def make_request( ) -> NodeResponseDict: url = f"{self.url}/{path}" - async with aiohttp.ClientSession() as session: + timeout_config = aiohttp.ClientTimeout(total=self.timeout) + + async with aiohttp.ClientSession(timeout=timeout_config) as session: try: if method == HTTPRequestMethod.GET: async with session.get( diff --git a/dkg/providers/node/node_http.py b/dkg/providers/node/node_http.py index d437a00..896c8fe 100644 --- a/dkg/providers/node/node_http.py +++ b/dkg/providers/node/node_http.py @@ -31,8 +31,10 @@ def __init__( endpoint_uri: URI | str, api_version: str = "v1", auth_token: str | None = None, + timeout: tuple[int, int] = (30, 60), # (connect_timeout, read_timeout) ): super().__init__(endpoint_uri, api_version, auth_token) + self.timeout = timeout def make_request( self, @@ -45,9 +47,13 @@ def make_request( try: if method == HTTPRequestMethod.GET: - response = requests.get(url, params=params, headers=self.headers) + response = requests.get( + url, params=params, headers=self.headers, timeout=self.timeout + ) elif method == HTTPRequestMethod.POST: - response = requests.post(url, json=data, headers=self.headers) + response = requests.post( + url, json=data, headers=self.headers, timeout=self.timeout + ) else: raise HTTPRequestMethodNotSupported( f"{method.name} method isn't supported"