locked
BlockBlob hangs while uploading the blob with 404 not found exception RRS feed

  • Question

  • 

    Hello Team,

    We are using WindowsAzure.Storage (9.3.0). We are using BlockBlob to upload multiple files. The files are a mixture of small and big files. The transfer works every time. However, recently it has started failing with this exception "The remote server returned an error: (404) Not Found."

    StorageException: The remote server returned an error: (404) Not Found. Module "Microsoft.WindowsAzure.Storage.Core.Executor.Executor", line 18, col 0, in EndExecuteAsync T EndExecuteAsync[T](System.IAsyncResult) Module "Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob", line 0, col 0, in EndDownloadBlockList System.Collections.Generic.IEnumerable`1[Microsoft.WindowsAzure.Storage.Blob.ListBlockItem] EndDownloadBlockList(System.IAsyncResult) Module "Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions+<>c__DisplayClass2`1", line 29, col 0, in CreateCallback { <lambda> } Void <CreateCallback>b__0(System.IAsyncResult) Module "System.Runtime.CompilerServices.TaskAwaiter", line 39, col 0, in ThrowForNonSuccess Void ThrowForNonSuccess(System.Threading.Tasks.Task) Module "System.Runtime.CompilerServices.TaskAwaiter", line 40, col 0, in HandleNonSuccessAndDebuggerNotification Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) Module "Pure.Storky.Data.Azure.CloudBlockBlobExtensions", line 131, col 0, in CommitBlockListAsync Void MoveNext() Module "System.Runtime.CompilerServices.TaskAwaiter", line 39, col 0, in ThrowForNonSuccess Void ThrowForNonSuccess(System.Threading.Tasks.Task) Module "System.Runtime.CompilerServices.TaskAwaiter", line 40, col 0, in HandleNonSuccessAndDebuggerNotification Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) Module "System.Runtime.CompilerServices.TaskAwaiter", line 0, col 0, in ValidateEnd Void ValidateEnd(System.Threading.Tasks.Task) Module "Pure.Storky.Data.Azure.CloudBlockBlobExtensions", line 836, col 0, in UploadFileAsync Void MoveNext() Module "System.Runtime.CompilerServices.TaskAwaiter", line 39, col 0, in ThrowForNonSuccess Void ThrowForNonSuccess(System.Threading.Tasks.Task) Module "System.Runtime.CompilerServices.TaskAwaiter", line 40, col 0, in HandleNonSuccessAndDebuggerNotification Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) Module "Pure.Storky.Data.Azure.AzureStorageClient", line 762, col 0, in UploadDirectory Void MoveNext() Module "System.Runtime.CompilerServices.TaskAwaiter", line 39, col 0, in ThrowForNonSuccess Void ThrowForNonSuccess(System.Threading.Tasks.Task) Module "System.Runtime.CompilerServices.TaskAwaiter", line 40, col 0, in HandleNonSuccessAndDebuggerNotification Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) Module "Pure.Storky.Data.Azure.AzureUploader", line 416, col 0, in Upload Void MoveNext() Module "System.Runtime.CompilerServices.TaskAwaiter", line 39, col 0, in ThrowForNonSuccess Void ThrowForNonSuccess(System.Threading.Tasks.Task) Module "System.Runtime.CompilerServices.TaskAwaiter", line 40, col 0, in HandleNonSuccessAndDebuggerNotification Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)

    public static async Task UploadFileAsync(this CloudBlockBlob blob, FileInfo file, Action<UploadProgress> onProgress, CancellationToken token)
            {
                var access = AccessCondition.GenerateEmptyCondition();
                var context = new OperationContext();
                var options = new BlobRequestOptions { RetryPolicy = new LinearRetry(TimeSpan.Zero, int.MaxValue) };
    
                var blocks = await GetBlocks(blob, token);
                var blockIds = blocks.Select(b => b.Name).ToList();
                var bytesUploaded = blocks.Sum(b => b.Length);
    
                using (var stream = file.OpenRead())
                {
                    stream.Seek(bytesUploaded, SeekOrigin.Begin);
    
                    const long blockSize = 4096L * 1024L;
                    var buffer = new byte[blockSize];
                    var bytesRead = stream.Read(buffer, 0, buffer.Length);
    
                    while (bytesRead > 0)
                    {
                        var blockId = Convert.ToBase64String(Encoding.ASCII.GetBytes($"BlockId{blockIds.Count:000000}"));
                        var bytes = buffer.Take(bytesRead).ToArray();
                        var hash = Convert.ToBase64String(MD5.Create().ComputeHash(bytes));
    
                        const int maxAttempts = 10;
                        for (var i = 1; i <= maxAttempts; i++)
                        {
                            try
                            {
                                using (var memoryStream = new MemoryStream(bytes))
                                {
                                    await blob.PutBlockAsync(blockId, memoryStream, hash, access, options, context, token);
                                }
    
                                break;
                            }
                            catch (Exception)
                            {
                                if (i == maxAttempts)
                                {
                                    throw;
                                }
                            }
    
                            Thread.Sleep(1000);
                        }
    
                        blockIds.Add(blockId);
                        bytesUploaded += bytesRead;
    
                        onProgress.Invoke(new UploadProgress(bytesUploaded, file.Length));
                        bytesRead = stream.Read(buffer, 0, buffer.Length);
                    }
    
                    await blob.PutBlockListAsync(blockIds);
                }
            }




    • Edited by Richa Garg Friday, July 26, 2019 6:29 PM
    Friday, July 26, 2019 6:27 PM

All replies

  • We would like to work closer with you on this matter. To understand the issue better! 
    Could you please reach to me via AZCommunity[AT]microsoft.com with a link to this Issue as well as your subscription ID and we can help get a support ticket opened for this issue. Please mention "ATTN subm" in the subject field. Looking forward to your reply
    Saturday, July 27, 2019 9:37 AM
  • Hi,

    This part of code snippet not much helpful to pointing out the error origin, It has some problem getting the BlockId variable before uploading in to it.

    I would suggest you to refactor the file upload logic around using the Microsoft Enterprise library code to catch error and also it has Retry connection option with well tested scenarios.

    Or

    You can try the AzCopy or AZ CLI (az storage blob copy batch) both approach has help you to track progress of the upload and async method.


    Murugesa Pandian,

    Gear up for some solid action by doing IT not saying IT.
    
    More insight @ Intelliview

    Sunday, July 28, 2019 6:15 AM
  • Issue has been resolved. Thanks.
    Monday, July 29, 2019 5:41 PM
  • @Richa Garg Glad to know that the issue is resolved. Thanks for the update! Kindly share the troubleshooting steps which helped you to fix this issue so that it will be beneficial to other community members reading this thread. And, if you have any further query do let us know.
    Tuesday, July 30, 2019 5:01 AM