[BUG] Blob client freeze when downloading blob (full framework only)
See original GitHub issueDescribe the bug
The code hang on BlobClient.DownloadAsync()
Expected behavior It should not “freeze”
Actual behavior (include Exception or Stack Trace) It freeze and prevent code from executing what next 😦
To Reproduce
- Create Azure blob storage premium
-
Create a container
test
-
Uploads 2 files names
test.txt
andtest2.txt
with contentabc
-
Run the following code (don’t forget to set the
ConnectionString
)
using System;
using System.Diagnostics;
using System.Net.Http;
using System.Threading.Tasks;
using Azure;
using Azure.Core.Pipeline;
using Azure.Storage.Blobs;
namespace ReproBugBlobHang
{
internal static class Program
{
private const string ContainerName = "test";
private const string ConnectionString = "";
private static readonly string[] Urls =
{
"test.txt",
"test2.txt",
};
private static void Main()
{
var blobClientOptions = new BlobClientOptions {Transport = new HttpClientTransport(new HttpClient() {Timeout = TimeSpan.FromSeconds(1)})};
var t1 = RunAsync(blobClientOptions);
var t2 = RunAsync(blobClientOptions);
Task.WaitAll(t1, t2);
}
private static async Task RunAsync(BlobClientOptions blobClientOptions)
{
foreach (var url in Urls)
{
var stopwatch = Stopwatch.StartNew();
try
{
var connection = new BlobClient(ConnectionString, ContainerName, url, blobClientOptions);
Console.WriteLine("BEGIN");
var response = await connection.DownloadAsync();
Console.WriteLine("END");
Console.WriteLine(response);
}
catch (RequestFailedException ex) when (ex.Status == 404)
{
Console.WriteLine("NOT FOUND");
}
Console.WriteLine(stopwatch.ElapsedMilliseconds);
}
}
}
}
csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.3.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
</Project>
Output:
D:/dev/git/rider/repro-jetbrains/ConsoleApplication2/ReproBugBlobHang/bin/Debug/net472/ReproBugBlobHang.exe
BEGIN
BEGIN
END
Status: 206, Value: Azure.Storage.Blobs.Models.BlobDownloadInfo
372
BEGIN
END
Status: 206, Value: Azure.Storage.Blobs.Models.BlobDownloadInfo
229
BEGIN
Then it hang until timeouts and throw
Unhandled Exception: System.AggregateException: One or more errors occurred. ---> System.AggregateException: Retry failed after 6 tries. ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.HttpClientTransport.<ProcessAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.RequestActivityPolicy.<ProcessNextAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.RequestActivityPolicy.<ProcessAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.BufferResponsePolicy.<ProcessAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.LoggingPolicy.<ProcessAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.LoggingPolicy.<ProcessAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.HttpPipelineSynchronousPolicy.<ProcessAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.HttpPipelineSynchronousPolicy.<ProcessAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Azure.Core.Pipeline.RetryPolicy.<ProcessAsync>d__11.MoveNext()
--- End of inner exception stack trace ---
at Azure.Core.Pipeline.RetryPolicy.<ProcessAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.HttpPipelineSynchronousPolicy.<ProcessAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.HttpPipelineSynchronousPolicy.<ProcessAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Storage.Blobs.BlobRestClient.Blob.<DownloadAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Storage.Blobs.Specialized.BlobBaseClient.<StartDownloadAsync>d__45.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Storage.Blobs.Specialized.BlobBaseClient.<DownloadInternal>d__44.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Storage.Blobs.Specialized.BlobBaseClient.<DownloadAsync>d__43.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Storage.Blobs.Specialized.BlobBaseClient.<DownloadAsync>d__41.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Storage.Blobs.Specialized.BlobBaseClient.<DownloadAsync>d__39.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at ReproBugBlobHang.Program.<RunAsync>d__4.MoveNext() in Program.cs:line 39
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout)
at System.Threading.Tasks.Task.WaitAll(Task[] tasks)
at ReproBugBlobHang.Program.Main() in Program.cs:line 27
Environment:
- Azure.Storage.Blobs 12.3.0
- Windows 10 .Net Framework 4.7.2 / .Net Framework
Note It’s working fine with TargetFramework: netcoreapp3.1
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:13 (5 by maintainers)
Top Results From Across the Web
Managing concurrency in Blob storage - Azure
This error indicates to the client that another process has updated the blob since the client first retrieved it. The client should fetch ......
Read more >How to download a file to browser from Azure Blob Storage
Here is the full tutorial I grabbed/modified this code sample from. By using direct blob access, you will completely bypass your VM/web role ......
Read more >How to use Azure Blob Storage with ASP.NET Core Web API
Learn how to use Azure Blob Storage with ASP.NET Core to upload, download and delete files from your application using a Web API....
Read more >File Upload/Download with BLOB Storage System in ASP.NET ...
This step-by-step article describes how to upload a file to a Web server and also download by client with using ASP.
Read more >Handle Blobs requests with Axios the right way
As you see, we can easily upload and download Blobs using Axios from our client-side applications. Most important thing is to understand ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @tg-msft for responding so quickly! This issue looks indeed very similar. We can try our repro after #12103 has been released (due to timing we had to port some code to .NET Core, which resolved the issue) or earlier if we have the opportunity to build azure sdk from source. You can leave that issue closed in the meantime, I will report back if the issue still shows up.
Sorry for closing the issue - we’re trying to make our bot a little more helpful and it was overeager here.
Can you take a look at https://github.com/Azure/azure-sdk-for-net/issues/11503? I think it’s a duplicate of this issue and we’re trying out a fix for it. We can reopen this issue otherwise.