Skip to content

Commit 85ad5df

Browse files
Merge remote-tracking branch 'origin/development' into local-staged-release
2 parents cdcd0a7 + a52d0a9 commit 85ad5df

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"services": [
3+
{
4+
"serviceName": "S3",
5+
"type": "patch",
6+
"changeLogMessages": [ "Fixed an issue where CancellationToken for async call was not passed along in underlying invocations while uploading unseekable steam using Multipart Upload." ]
7+
}
8+
]
9+
}

sdk/src/Services/S3/Custom/Transfer/Internal/_async/MultipartUploadCommand.async.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ private void AbortMultipartUpload(string uploadId)
187187
}
188188
private async Task UploadUnseekableStreamAsync(TransferUtilityUploadRequest request, CancellationToken cancellationToken = default(CancellationToken))
189189
{
190+
cancellationToken.ThrowIfCancellationRequested();
190191

191192
int READ_BUFFER_SIZE = this._s3Client.Config.BufferSize;
192193

@@ -201,7 +202,7 @@ private void AbortMultipartUpload(string uploadId)
201202
};
202203

203204
var initiateRequest = ConstructInitiateMultipartUploadRequest(requestEventHandler);
204-
var initiateResponse = await _s3Client.InitiateMultipartUploadAsync(initiateRequest).ConfigureAwait(false);
205+
var initiateResponse = await _s3Client.InitiateMultipartUploadAsync(initiateRequest, cancellationToken).ConfigureAwait(false);
205206

206207
try
207208
{
@@ -219,14 +220,14 @@ private void AbortMultipartUpload(string uploadId)
219220
int partNumber = 1;
220221
int readBytesCount, readAheadBytesCount = 0;
221222

222-
readBytesCount = await stream.ReadAsync(readBuffer, 0, readBuffer.Length).ConfigureAwait(false);
223+
readBytesCount = await stream.ReadAsync(readBuffer, 0, readBuffer.Length, cancellationToken).ConfigureAwait(false);
223224

224225
do
225226
{
226-
await nextUploadBuffer.WriteAsync(readBuffer, 0, readBytesCount).ConfigureAwait(false);
227+
await nextUploadBuffer.WriteAsync(readBuffer, 0, readBytesCount, cancellationToken).ConfigureAwait(false);
227228
// read the stream ahead and process it in the next iteration.
228229
// this is used to set isLastPart when there is no data left in the stream.
229-
readAheadBytesCount = await stream.ReadAsync(readBuffer, 0, readBuffer.Length).ConfigureAwait(false);
230+
readAheadBytesCount = await stream.ReadAsync(readBuffer, 0, readBuffer.Length, cancellationToken).ConfigureAwait(false);
230231
if ((nextUploadBuffer.Position > minPartSize || readAheadBytesCount == 0))
231232
{
232233
if (nextUploadBuffer.Position == 0)
@@ -247,7 +248,7 @@ private void AbortMultipartUpload(string uploadId)
247248
nextUploadBuffer.Position = 0;
248249
UploadPartRequest uploadPartRequest = ConstructUploadPartRequestForNonSeekableStream(nextUploadBuffer, partNumber, partSize, isLastPart, initiateResponse);
249250

250-
var partResponse = await _s3Client.UploadPartAsync(uploadPartRequest).ConfigureAwait(false);
251+
var partResponse = await _s3Client.UploadPartAsync(uploadPartRequest, cancellationToken).ConfigureAwait(false);
251252
Logger.DebugFormat("Uploaded part {0}. (Last part = {1}, Part size = {2}, Upload Id: {3})", partNumber, isLastPart, partSize, initiateResponse.UploadId);
252253
uploadPartResponses.Add(partResponse);
253254
partNumber++;
@@ -269,7 +270,7 @@ private void AbortMultipartUpload(string uploadId)
269270

270271
this._uploadResponses = uploadPartResponses;
271272
CompleteMultipartUploadRequest compRequest = ConstructCompleteMultipartUploadRequest(initiateResponse, true, requestEventHandler);
272-
await _s3Client.CompleteMultipartUploadAsync(compRequest).ConfigureAwait(false);
273+
await _s3Client.CompleteMultipartUploadAsync(compRequest, cancellationToken).ConfigureAwait(false);
273274
Logger.DebugFormat("Completed multi part upload. (Part count: {0}, Upload Id: {1})", uploadPartResponses.Count, initiateResponse.UploadId);
274275
}
275276
}

0 commit comments

Comments
 (0)