1

My app uses ListBlobsSegmentedAsync and the following loop never finishes:

    // List blobs existing in container
    HashSet<string> existingBlobNames = new HashSet<string>();
    BlobResultSegment segment;
    do
    {
        segment = await container.ListBlobsSegmentedAsync(null, cancellationToken).ConfigureAwait(false);
        foreach (IListBlobItem blobListItem in segment.Results)
        {
            CloudBlockBlob blob = blobListItem as CloudBlockBlob;
            if (blob != null)
            {
                existingBlobNames.Add(blob.Name);
            }
        }
    }
    while (segment.ContinuationToken != null);

It always returns exactly the same ContinuationToken & no results.

1 Answer 1

1

This was me who ported this logic from another service which worked successfully for years. Turned out that service always had the same bug. But since there could have been at most 10 blobs in a container it never hit it.

This code needs actually to pass a continuation token =) Here is the corrected version.

        BlobContinuationToken continuationToken = null;
        do
        {
            BlobResultSegment segment = await container.ListBlobsSegmentedAsync(continuationToken, cancellationToken).ConfigureAwait(false);
            foreach (IListBlobItem blobListItem in segment.Results)
            {
                CloudBlockBlob blob = blobListItem as CloudBlockBlob;
                if (blob != null)
                {
                    existingBlobNames.Add(blob.Name);
                }
            }

            continuationToken = segment.ContinuationToken;
        }
        while (continuationToken != null);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.