Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[S3] Fix issue #616: fix the error handling for transfers when network disconnects #865

Merged
merged 1 commit into from
Apr 4, 2019

Conversation

mutablealligator
Copy link
Contributor

Issue #, if available:

#616

Description of changes:

fix the error handling for transfers when network disconnects

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@mutablealligator mutablealligator added s3 Issues with the AWS Android SDK for Simple Storage Service (S3). Pull Request labels Apr 3, 2019
@mutablealligator mutablealligator self-assigned this Apr 3, 2019
@mutablealligator mutablealligator requested a review from scb01 April 3, 2019 22:19
if (TransferNetworkLossHandler.getInstance() != null &&
!TransferNetworkLossHandler.getInstance().isNetworkConnected()) {
LOGGER.info("Network not connected. Setting the state to WAITING_FOR_NETWORK.");
updater.updateState(upload.id, TransferState.WAITING_FOR_NETWORK);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The status shouldn't be updated here, but instead done by the caller by looking at the return value of the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

*/
private void completeMultiPartUpload(int mainUploadId, String bucket,
private CompleteMultipartUploadResult completeMultiPartUpload(int mainUploadId, String bucket,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the " throws AmazonClientException, AmazonServiceException" to this private method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

updater.updateProgress(upload.id, upload.bytesTotal, upload.bytesTotal, true);
updater.updateState(upload.id, TransferState.COMPLETED);
return true;
if (result != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

completeMultiPartUpload throws the AmazonClientException/AmazonServerException if there is an error. The check for result != null is redundant and the else clause would be dead code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

try {
if (TransferNetworkLossHandler.getInstance() != null &&
!TransferNetworkLossHandler.getInstance().isNetworkConnected()) {
LOGGER.info("Network not connected. Setting the state to WAITING_FOR_NETWORK.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this log statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

Copy link
Contributor

@scb01 scb01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to catch exceptions thrown by the abort call to ensure that it doesn't crash the app.

@@ -241,6 +242,8 @@ private Boolean uploadMultipartAndWaitForCompletion() throws ExecutionException
} catch (final AmazonClientException ace) {
LOGGER.error("Failed to complete multipart: " + upload.id
+ " due to " + ace.getMessage(), ace);
abortMultiPartUpload(upload.id, upload.bucketName, upload.key,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to catch any exceptions thrown by abort as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The abortMultiPartUpload method catches all the exceptions thrown by s3. abortMultiPartUpload.

@mutablealligator mutablealligator merged commit b4fc44e into develop Apr 4, 2019
@mutablealligator mutablealligator deleted the s3-fix-616 branch April 4, 2019 15:59
awsmobilesdk pushed a commit to awsmobilesdk/aws-sdk-android that referenced this pull request Apr 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s3 Issues with the AWS Android SDK for Simple Storage Service (S3).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants