Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions b2sdk/_internal/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,14 @@ class ServiceError(TransientErrorMixin, B2Error):
"""


class RequestTimeout(TransientErrorMixin, B2Error):
"""A server HTTP 408 response, raised by :func:`interpret_b2_error` for status 408.

Unlike :class:`B2RequestTimeout`, this is not a client-side socket or connection timeout
raised in ``b2http.py``.
"""


class CapExceeded(B2Error):
def __str__(self):
return 'Cap exceeded.'
Expand Down Expand Up @@ -750,6 +758,8 @@ def interpret_b2_error(
return Conflict()
elif status == 416 and code == 'range_not_satisfiable':
return UnsatisfiableRange()
elif status == 408:
return RequestTimeout('%d %s %s' % (status, code, message))
elif status == 429:
return TooManyRequests(retry_after_seconds=response_headers.get('retry-after'))
elif 500 <= status < 600:
Expand Down
2 changes: 2 additions & 0 deletions b2sdk/v3/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
NotAllowedByAppKeyError,
PartSha1Mismatch,
PotentialS3EndpointPassedAsRealm,
RequestTimeout,
RestrictedBucket,
RestrictedBucketMissing,
RetentionWriteError,
Expand Down Expand Up @@ -154,6 +155,7 @@
'NotAllowedByAppKeyError',
'PartSha1Mismatch',
'PotentialS3EndpointPassedAsRealm',
'RequestTimeout',
'RestrictedBucket',
'RestrictedBucketMissing',
'RetentionWriteError',
Expand Down
1 change: 1 addition & 0 deletions changelog.d/605.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Retry uploads after a B2 request-timeout response (HTTP 408).
9 changes: 9 additions & 0 deletions test/unit/bucket/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
InvalidRange,
InvalidUploadSource,
MaxRetriesExceeded,
RequestTimeout,
RestrictedBucketMissing,
SourceReplicationConflict,
SSECKeyError,
Expand Down Expand Up @@ -2102,6 +2103,14 @@ def test_upload_timeout(self):
data = b'hello world'
self.bucket.upload_bytes(data, 'file1')

def test_upload_http_request_timeout(self):
self.simulator.set_upload_errors([RequestTimeout('408 request_timeout request timeout')])
data = b'hello world'

self.bucket.upload_bytes(data, 'file1')

self._check_file_contents('file1', data)

def test_upload_file_one_fatal_error(self):
self.simulator.set_upload_errors([CanRetry(False)])
data = b'hello world'
Expand Down
8 changes: 7 additions & 1 deletion test/unit/test_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
interpret_b2_error,
)

from b2sdk._internal.exception import ResourceNotFound
from b2sdk._internal.exception import RequestTimeout, ResourceNotFound


class TestB2Error:
Expand Down Expand Up @@ -161,6 +161,12 @@ def test_service_error(self):
assert isinstance(error, ServiceError)
assert '500 code message' == str(error)

def test_request_timeout(self):
error = interpret_b2_error(408, 'request_timeout', 'request timeout', {})
assert isinstance(error, RequestTimeout)
assert error.should_retry_upload()
assert error.should_retry_http()

def test_unknown_error(self):
error = interpret_b2_error(499, 'code', 'message', {})
assert isinstance(error, UnknownError)
Expand Down
Loading