Skip to content

Commit

Permalink
Merge pull request #674 from jjjake/s3-check-limit-errors
Browse files Browse the repository at this point in the history
Fixes #673, IA-S3 check_limit error message bug.
  • Loading branch information
jjjake authored Jan 10, 2025
2 parents 49346c9 + 27a44e9 commit 88b695b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
7 changes: 7 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
Release History
---------------

5.2.0 (?)
+++++++++

**Bugfixes**

- Fixed bug where failed requests to IA-S3 check_limit API would be treated as a 503 slowdown error.

5.1.0 (2025-01-07)
++++++++++++++++++

Expand Down
2 changes: 1 addition & 1 deletion internetarchive/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '5.1.0'
__version__ = '5.2.0.dev1'
18 changes: 15 additions & 3 deletions internetarchive/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ def remove_from_simplelist(self, parent, list) -> Response:
r = self.session.post(self.urls.metadata, data=data) # type: ignore
return r

def upload_file(self, body,
def upload_file(self, body, # noqa: PLR0915; TODO: Refactor this method to reduce complexity
key: str | None = None,
metadata: Mapping | None = None,
file_metadata: Mapping | None = None,
Expand Down Expand Up @@ -1079,12 +1079,23 @@ def _build_request():
return prepared_request
else:
try:
first_try = True
while True:
error_msg = ('s3 is overloaded, sleeping for '
f'{retries_sleep} seconds and retrying. '
f'{retries} retries left.')
if retries > 0:
if self.session.s3_is_overloaded(access_key=access_key):
if retries > 0 and not first_try:
try:
overloaded = self.session.s3_is_overloaded(
access_key=access_key)
except Exception as e:
error_msg = ('error checking if s3 is overloaded via '
's3.us.archive.org?check_limit=1, '
f'exception raised: "{e}". '
f'sleeping for {retries_sleep} seconds and '
f'retrying. {retries} retries left.')
overloaded = True
if overloaded:
sleep(retries_sleep)
log.info(error_msg)
if verbose:
Expand Down Expand Up @@ -1112,6 +1123,7 @@ def _build_request():
print(f' warning: {error_msg}', file=sys.stderr)
sleep(retries_sleep)
retries -= 1
first_try = False
continue
else:
if response.status_code == 503:
Expand Down
5 changes: 1 addition & 4 deletions internetarchive/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,7 @@ def s3_is_overloaded(self, identifier=None, access_key=None, request_kwargs=None
'accesskey': access_key,
'bucket': identifier,
}
try:
r = self.get(u, params=p, **request_kwargs)
except Exception:
return True
r = self.get(u, params=p, **request_kwargs)
try:
j = r.json()
except ValueError:
Expand Down

0 comments on commit 88b695b

Please sign in to comment.