Skip to content

Commit 698bd98

Browse files
committed
When multipart uploads fail, cancel remaining part transfers
Suppose we have 10 parts, if we fail on part aws#2 we fire a "TRANFER_FAILED_EVENT" back to the client. We should assume that clients will react to this failure, possibly with custom logic to retry. Supposing that part aws#3 succeeds, the client will then get other transfer events past the "TRANSFER_FAILED_EVENT". I assume here that "TRANSFER_FAILED_EVENT" is a terminal event and that a client should not expect to receive further events for that transfer, successful or not. However, the meaning of TRANSFER_FAILED_EVENT is not clearly defined in the javadocs. relates to: aws#2263
1 parent 7a68a2b commit 698bd98

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

aws-java-sdk-s3/src/main/java/com/amazonaws/services/s3/transfer/internal/CompleteMultipartUpload.java

+14-8
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,23 @@ public UploadResult call() throws Exception {
115115
*/
116116
private List<PartETag> collectPartETags() {
117117

118-
final List<PartETag> partETags = new ArrayList<PartETag>();
118+
final List<PartETag> partETags = new ArrayList<PartETag>(eTagsBeforeResume.size());
119119
partETags.addAll(eTagsBeforeResume);
120-
for (Future<PartETag> future : futures) {
121-
try {
122-
partETags.add(future.get());
123-
} catch (Exception e) {
124-
throw new SdkClientException(
125-
"Unable to complete multi-part upload. Individual part upload failed : "
126-
+ e.getCause().getMessage(), e.getCause());
120+
121+
int index = 0;
122+
try {
123+
for (; index < futures.size(); index++) {
124+
partETags.add(futures.get(index).get());
127125
}
126+
} catch (Exception e) {
127+
for (; index < futures.size(); index++) {
128+
futures.get(index).cancel(true);
129+
}
130+
throw new SdkClientException(
131+
"Unable to complete multi-part upload. Individual part upload failed : "
132+
+ e.getCause().getMessage(), e.getCause());
128133
}
134+
129135
return partETags;
130136
}
131137
}

0 commit comments

Comments
 (0)