Skip to content

Commit f2ee08a

Browse files
authored
Fixed bug where Blob CopyFromUriOperation throws exception when statu… (Azure#27711)
1 parent f60ca34 commit f2ee08a

File tree

5 files changed

+662
-0
lines changed

5 files changed

+662
-0
lines changed

sdk/storage/Azure.Storage.Blobs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Added support for service version 2021-06-08.
55
- Added pageable versions of PageBlobClient.GetPageRanges() and .GetPageRangesAsync().
66
- Added ability to copy source blob tags for BlobBaseClient.SyncCopyFromUri() and .SyncCopyFromUriAsync().
7+
- Fixed a bug where CopyFromUriOperation was throwing an Exception when the status of the blob copy was aborted or failed.
78

89
## 12.11.0 (2022-03-10)
910
- Includes all features from 12.11.0-beta.1, 12.11.0-beta.2, and 12.11.0-beta.3 except SDK-calculated transactional checksums on data transfer.

sdk/storage/Azure.Storage.Blobs/src/Models/CopyFromUriOperation.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ private async Task<Response> UpdateStatusAsync(bool async, CancellationToken can
185185
{
186186
_value = update.Value.ContentLength;
187187
}
188+
// Check if the operation aborted or failed
189+
if (Id == update.Value.CopyId &&
190+
(update.Value.CopyStatus == CopyStatus.Aborted ||
191+
update.Value.CopyStatus == CopyStatus.Failed))
192+
{
193+
_value = 0;
194+
}
188195

189196
// Save this update as the latest raw response indicating the state
190197
// of the copy operation

sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,6 +2303,48 @@ public async Task StartCopyFromUriAsync_VersionId()
23032303
Assert.IsTrue(operation.GetRawResponse().Headers.TryGetValue(Constants.HeaderNames.VersionId, out var _));
23042304
}
23052305

2306+
[RecordedTest]
2307+
public async Task StartCopyFromUriAsync_OperationAbort()
2308+
{
2309+
await using DisposingContainer test = await GetTestContainerAsync();
2310+
2311+
// Arrange
2312+
await test.Container.SetAccessPolicyAsync(PublicAccessType.Blob);
2313+
var data = GetRandomBuffer(8 * Constants.MB);
2314+
2315+
BlockBlobClient srcBlob = InstrumentClient(test.Container.GetBlockBlobClient(GetNewBlobName()));
2316+
using (var stream = new MemoryStream(data))
2317+
{
2318+
await srcBlob.UploadAsync(stream);
2319+
}
2320+
2321+
BlobServiceClient secondaryService = BlobsClientBuilder.GetServiceClient_SecondaryAccount_SharedKey();
2322+
await using DisposingContainer destTest = await GetTestContainerAsync(service: secondaryService);
2323+
{
2324+
BlockBlobClient destBlob = InstrumentClient(destTest.Container.GetBlockBlobClient(GetNewBlobName()));
2325+
2326+
CopyFromUriOperation operation = await destBlob.StartCopyFromUriAsync(srcBlob.Uri);
2327+
2328+
// Act
2329+
try
2330+
{
2331+
Response response = await destBlob.AbortCopyFromUriAsync(operation.Id);
2332+
2333+
// Act
2334+
await operation.WaitForCompletionAsync();
2335+
2336+
// Assert
2337+
Assert.AreEqual(operation.Value,0);
2338+
Assert.True(operation.HasCompleted);
2339+
Assert.IsNotNull(operation.GetRawResponse());
2340+
}
2341+
catch (RequestFailedException e) when (e.ErrorCode == "NoPendingCopyOperation")
2342+
{
2343+
WarnCopyCompletedTooQuickly();
2344+
}
2345+
}
2346+
}
2347+
23062348
[RecordedTest]
23072349
public async Task AbortCopyFromUriAsync()
23082350
{

sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/StartCopyFromUriAsync_OperationAbort.json

Lines changed: 306 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/StartCopyFromUriAsync_OperationAbortAsync.json

Lines changed: 306 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)