Skip to content

Commit

Permalink
Check type of parameters timeout_seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
maximusunc committed Aug 8, 2023
1 parent abcc851 commit 855ddf5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
21 changes: 11 additions & 10 deletions strider/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,9 @@ async def sync_query(
try:
LOGGER.info(f"[{qid}] Starting sync query")
# get max timeout
timeout = max(
max_process_time, query_dict.get("parameters", {}).get("timeout_seconds", 0)
)
timeout_seconds = (query_dict.get("parameters") or {}).get("timeout_seconds")
timeout_seconds = timeout_seconds if type(timeout_seconds) is int else 0
timeout = max(max_process_time, timeout_seconds)
query_results = await asyncio.wait_for(lookup(query_dict, qid), timeout=timeout)
except asyncio.TimeoutError:
LOGGER.error(f"[{qid}] Sync query cancelled due to timeout.")
Expand Down Expand Up @@ -448,7 +448,7 @@ async def lookup(
logger.setLevel(level_number)
logger.addHandler(log_handler)

parameters = query_dict.get("parameters", {})
parameters = query_dict.get("parameters") or {}

fetcher = Fetcher(logger, parameters)

Expand Down Expand Up @@ -527,9 +527,9 @@ async def async_lookup(
query_results = {}
try:
# get max timeout
timeout = max(
max_process_time, query_dict.get("parameters", {}).get("timeout_seconds", 0)
)
timeout_seconds = (query_dict.get("parameters") or {}).get("timeout_seconds")
timeout_seconds = timeout_seconds if type(timeout_seconds) is int else 0
timeout = max(max_process_time, timeout_seconds)
query_results = await asyncio.wait_for(lookup(query_dict, qid), timeout=timeout)
except asyncio.TimeoutError:
LOGGER.error(f"[{qid}]: Process cancelled due to timeout.")
Expand Down Expand Up @@ -560,10 +560,11 @@ async def single_lookup(query_key):
query_result = {}
try:
# get max timeout
timeout = max(
max_process_time,
queries[query_key].get("parameters", {}).get("timeout_seconds", 0),
timeout_seconds = (queries[query_key].get("parameters") or {}).get(
"timeout_seconds"
)
timeout_seconds = timeout_seconds if type(timeout_seconds) is int else 0
timeout = max(max_process_time, timeout_seconds)
query_result = await asyncio.wait_for(
lookup(queries[query_key], qid), timeout=timeout
)
Expand Down
5 changes: 4 additions & 1 deletion strider/throttle.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ async def process_batch(
),
)
)
kp_timeout = self.parameters.get("timeout_seconds", settings.kp_timeout)
kp_timeout = self.parameters.get("timeout_seconds")
kp_timeout = (
kp_timeout if type(kp_timeout) is int else settings.kp_timeout
)
async with httpx.AsyncClient(timeout=kp_timeout) as client:
response = await client.post(
self.url,
Expand Down

0 comments on commit 855ddf5

Please sign in to comment.