Skip to content

Commit 58a573b

Browse files
committed
trying to catch where TimeoutError and CancelledError become TypeError
due to trying to parse it as JSON when it should have been raised. aiohttp is weird with pause/unpause from a container.
1 parent 303f45e commit 58a573b

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

runpod/serverless/modules/rp_job.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,18 @@ async def get_job(
7777
log.error(f"- Failed to get job, status code: {response.status}")
7878
return
7979

80-
try:
81-
jobs = await response.json()
82-
log.debug(f"- Job(s) Received")
83-
except TypeError as err:
84-
log.debug(f"- {response} | {err}")
85-
raise response
86-
except Exception as err:
87-
log.debug(f"- {response} | {err}")
88-
raise err
80+
# Verify if the content type is JSON
81+
if response.content_type != "application/json":
82+
log.error(f"- Unexpected content type: {response.content_type}")
83+
return
84+
85+
# Check if there is a non-empty content to parse
86+
if response.content_length == 0:
87+
log.debug("- No content to parse.")
88+
return
89+
90+
jobs = await response.json()
91+
log.debug(f"- Received Job(s)")
8992

9093
# legacy job-take API
9194
if isinstance(jobs, dict):

runpod/serverless/modules/rp_scale.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,14 @@ async def get_jobs(self, session: ClientSession):
150150
acquired_jobs = await asyncio.wait_for(
151151
get_job(session, jobs_needed), timeout=30
152152
)
153+
except asyncio.CancelledError:
154+
log.debug("JobScaler.get_jobs | Request was cancelled.")
155+
continue
153156
except TimeoutError:
154157
log.debug("JobScaler.get_jobs | Job acquisition timed out. Retrying.")
155158
continue
156159
except TypeError as error:
157-
log.debug(f"Unexpected error: {error}. acquired_jobs={acquired_jobs}")
160+
log.debug(f"JobScaler.get_jobs | Unexpected error: {error}.")
158161
continue
159162
except Exception as error:
160163
log.error(

0 commit comments

Comments
 (0)