question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] CopyStatus is not updated after copy is finished

See original GitHub issue

Describe the bug I’m making the migration from Microsoft.WindowsAzure.Storage.Blob versio 9.3.2.0 to Azure.Storage.Blobs version 12.8.0.0 and trying to replicate the CopyBlobData functionality. In the oldest version, we could check a property CopyStatus to see if the copy is finished. In the new one we still have this property, but it’s never updated and so we can never know if the copy has ended. See more bellow:

1. Original code

public virtual void CopyFromBlob(string sourceConnectionString, string sourceContainerName, string sourceBlobName, string targetConnectionString, string targetContainerName, string targetBlobName)
{
    var sourceContainer = GetContainer(sourceConnectionString, sourceContainerName);
    CloudBlockBlob sourceBlockBlob = sourceContainer.GetBlockBlobReference(sourceBlobName);

    var targetContainer = GetContainer(targetConnectionString, targetContainerName);
    CloudBlockBlob targetBlockBlob = targetContainer.GetBlockBlobReference(targetBlobName);

    targetBlockBlob.StartCopy(sourceBlockBlob);

    while (targetBlockBlob.CopyState.Status == Microsoft.WindowsAzure.Storage.Blob.CopyStatus.Pending)
    {
        Thread.Sleep(500);
    }

    if (targetBlockBlob.CopyState.Status != Microsoft.WindowsAzure.Storage.Blob.CopyStatus.Success)
    {
        throw new Exception("Copy failed: " + targetBlockBlob.CopyState.Status);
    }
}

2. New version

public virtual void CopyFromBlobNew(string sourceConnectionString, string sourceContainerName, string sourceBlobName, string targetConnectionString, string targetContainerName, string targetBlobName)
{
    var sourceContainer = GetContainerNew(sourceConnectionString, sourceContainerName);
    var sourceBlob = sourceContainer.GetBlobClient(sourceBlobName);
    
    var targetContainer = GetContainerNew(targetConnectionString, targetContainerName);
    var targetBlob = targetContainer.GetBlobClient(targetBlobName);

        var copyInformation = targetBlob.SyncCopyFromUri(sourceBlob.Uri);

        while (copyInformation.Value.CopyStatus == Azure.Storage.Blobs.Models.CopyStatus.Pending) 
        {
            Thread.Sleep(500);
        }

        if (copyInformation.Value.CopyStatus != Azure.Storage.Blobs.Models.CopyStatus.Success)
        {
            throw new Exception("Copy failed: " + copyInformation.Value.CopyStatus);
        }
}

The problem is: the CopyStatus property inside the BlobCopyInfo object that the SyncCopyFromUri method returns is never updated. I’ve eve tried to get the blob properties directly, but, as you can see bellow, the CopyStatus property still with the wrong value even if there is no more data to copy:

image

Expected behavior The CopyStatus property should be updated as soon as the copy is finished.

Actual behavior (include Exception or Stack Trace) The CopyStatus is never updated

To Reproduce Described above

Environment:

  • Azure.Storage.Blobs version 12.8.0.0
  • Windows 10, .NET Framework 4.7
  • IDE and version : Version 16.8.5

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
seanmcc-msftcommented, Mar 16, 2021

@WillRock19, this is by design.

copyInformation is not a dynamic object, and will not be updated.

I would recommend this approach instead:

public virtual async Task CopyFromBlobNewAsync(
    string sourceConnectionString,
    string sourceContainerName,
    string sourceBlobName,
    string targetConnectionString,
    string targetContainerName,
    string targetBlobName)
{
    BlobContainerClient sourceContainer = GetContainerNew(sourceConnectionString, sourceContainerName);
    BlobClient sourceBlob = sourceContainer.GetBlobClient(sourceBlobName);
    
    BlobContainerClient targetContainer = GetContainerNew(targetConnectionString, targetContainerName);
    BlobClient targetBlob = targetContainer.GetBlobClient(targetBlobName);

        await targetBlob.SyncCopyFromUriAsync(sourceBlob.Uri);
        Response<BlobProperties> blobPropertiesResponse = await targetBlob.GetPropertiesAsync();
        while (blobPropertiesResponse.Value.CopyStatus == Azure.Storage.Blobs.Models.CopyStatus.Pending) 
        {
            Thread.Sleep(500);
            blobPropertiesResponse = await targetBlob.GetPropertiesAsync();
        }

        if (blobPropertiesResponse.Value.CopyStatus != Azure.Storage.Blobs.Models.CopyStatus.Success)
        {
            throw new Exception("Copy failed: " + copyInformation.Value.CopyStatus);
        }
}

-Sean

0reactions
WillRock19commented, Apr 12, 2021

Hi @seanmcc-msft, any updates on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Large file copy to a USB drive, nautilus shows incorrect ...
1-stable), to an external USB thumb drive, the copy progress status will typically say 100% complete and 0" seconds" left when it's not...
Read more >
How to get updated copy state of azure blob when using ...
It can be one of the following: pending: Copy operation is pending. success: Copy operation completed successfully. aborted: Copy operation was ...
Read more >
How to restore file copy / transfer status window?
First of all: Check your Files icon in the launcher (on your left for most systems). There will be a little progress bar...
Read more >
ERROR or BUG: Excel not updating after a file copy
I make a copy of a template excel workbook and open the copy. Some of the formulas no longer calculate, specifically anything with...
Read more >
Reseeding after 'Mailbox Database ... - Kernel Data Recovery
If the cmdlet did not run correctly, then it will not create a copy at the destination server, and there will be an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found