summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
authordrebs <drebs@riseup.net>2017-10-05 09:03:39 -0300
committerdrebs <drebs@riseup.net>2017-10-05 09:43:41 -0300
commite98dd6b7b7366c9ae6ca18c6e94866fbf8641afe (patch)
treeee6b3ea3cb8a2e35d58b1b215a85fbdf5a33136b /src/leap
parentee79459569cd93467afd056412a88d05d2263917 (diff)
[bug] retry blob download for all retriable errors
Because the exception catching was being made inside _download_and_decrypt() and only accounted for InvalidBlob exceptions, not all retriable errors would lead to an actual retry. This commit moves the exception catching to one level up and catches any kind of exception, as is done in the upload part. This allows for retrying on all retriable errors.
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/soledad/client/_db/blobs.py43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/leap/soledad/client/_db/blobs.py b/src/leap/soledad/client/_db/blobs.py
index d18b1616..527a6418 100644
--- a/src/leap/soledad/client/_db/blobs.py
+++ b/src/leap/soledad/client/_db/blobs.py
@@ -489,7 +489,28 @@ class BlobManager(object):
logger.info("Found blob in local database: %s" % blob_id)
defer.returnValue(local_blob)
- result = yield self._download_and_decrypt(blob_id, namespace)
+ try:
+ result = yield self._download_and_decrypt(blob_id, namespace)
+ except Exception as e:
+ _, retries = yield self.local.get_sync_status(blob_id)
+
+ if isinstance(e, InvalidBlob):
+ message = "Corrupted blob received from server! ID: %s\n"
+ message += "Error: %r\n"
+ message += "Retries: %s - Attempts left: %s\n"
+ message += "This is either a bug or the contents of the "
+ message += "blob have been tampered with. Please, report to "
+ message += "your provider's sysadmin and submit a bug report."
+ message %= (blob_id, e, retries, (self.max_retries - retries))
+ logger.error(message)
+
+ yield self.local.increment_retries(blob_id)
+ if (retries + 1) >= self.max_retries:
+ failed_download = SyncStatus.FAILED_DOWNLOAD
+ yield self.local.update_sync_status(blob_id, failed_download)
+ raise e
+ else:
+ raise RetriableTransferError(e)
if not result:
defer.returnValue(None)
@@ -548,25 +569,7 @@ class BlobManager(object):
# incrementally collect the body of the response
yield treq.collect(response, buf.write)
- try:
- fd, size = buf.close()
- except InvalidBlob as e:
- _, retries = yield self.local.get_sync_status(blob_id)
- message = "Corrupted blob received from server! ID: %s\n"
- message += "Error: %r\n"
- message += "Retries: %s - Attempts left: %s\n"
- message += "This is either a bug or the contents of the "
- message += "blob have been tampered with. Please, report "
- message += "to your provider's sysadmin and submit a bug report."
- message %= (blob_id, e, retries, (self.max_retries - retries))
- logger.error(message)
- yield self.local.increment_retries(blob_id)
- if (retries + 1) >= self.max_retries:
- failed_download = SyncStatus.FAILED_DOWNLOAD
- yield self.local.update_sync_status(blob_id, failed_download)
- raise e
- else:
- raise RetriableTransferError()
+ fd, size = buf.close()
logger.info("Finished download: (%s, %d)" % (blob_id, size))
defer.returnValue((fd, size))