Skip to content

Commit

Permalink
curl: raise exception when HTTP error code is client error
Browse files Browse the repository at this point in the history
When curl catched HTTP error 4xx = client error such as "404 Not Found"
or "403 Forbidden", it likely our script bug not server side issue, we
should re-raise exception immediately instead of retrying.

related scylladb#505
  • Loading branch information
syuu1228 committed Mar 16, 2024
1 parent 7b241cb commit 003f509
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/scylla_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ def curl(url, headers=None, method=None, byte=False, timeout=3, max_retries=5, r
while True:
try:
return _curl_one(url, headers, method, byte, timeout)
except (urllib.error.URLError, socket.timeout):
except (urllib.error.URLError, socket.timeout) as e:
# if HTTP error code is client error (400-499), skip retrying
if isinstance(e, urllib.error.HTTPError) and e.code in range(400,500):
raise
time.sleep(retry_interval)
retries += 1
if retries >= max_retries:
Expand All @@ -84,7 +87,10 @@ async def aiocurl(url, headers=None, method=None, byte=False, timeout=3, max_ret
while True:
try:
return _curl_one(url, headers, method, byte, timeout)
except (urllib.error.URLError, socket.timeout):
except (urllib.error.URLError, socket.timeout) as e:
# if HTTP error code is client error (400-499), skip retrying
if isinstance(e, urllib.error.HTTPError) and e.code in range(400,500):
raise
await asyncio.sleep(retry_interval)
retries += 1
if retries >= max_retries:
Expand Down

0 comments on commit 003f509

Please sign in to comment.