From 87a6d8009f2235d4a38c6e09531165c5771e607a Mon Sep 17 00:00:00 2001 From: OpenSourceSoul Date: Sun, 1 Feb 2026 18:24:38 +0000 Subject: [PATCH] Add timeout to SerpAPI HTTP requests to prevent indefinite hanging The SerpAPI wrapper was making HTTP requests without any timeout, which could cause the validator/miner to hang indefinitely if the SerpAPI service is slow or unresponsive. This adds a 30-second timeout to both ClientSession creation and individual GET requests. --- desearch/tools/search/serp_api_wrapper.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/desearch/tools/search/serp_api_wrapper.py b/desearch/tools/search/serp_api_wrapper.py index 0e9351ad..43ee2b11 100644 --- a/desearch/tools/search/serp_api_wrapper.py +++ b/desearch/tools/search/serp_api_wrapper.py @@ -1,4 +1,5 @@ import aiohttp +from aiohttp import ClientTimeout from typing import Any, Dict, Optional, Tuple @@ -37,12 +38,13 @@ def construct_url_and_params() -> Tuple[str, Dict[str, str]]: return url, params url, params = construct_url_and_params() + timeout = ClientTimeout(total=30) if not self.aiosession: - async with aiohttp.ClientSession() as session: - async with session.get(url, params=params) as response: + async with aiohttp.ClientSession(timeout=timeout) as session: + async with session.get(url, params=params, timeout=timeout) as response: res = await response.json() else: - async with self.aiosession.get(url, params=params) as response: + async with self.aiosession.get(url, params=params, timeout=timeout) as response: res = await response.json() return res