[BUG] BlobClient.UploadAsync(Stream content, bool overwrite) deadlocks if the stream is not rewinded
See original GitHub issueConsider the following code, where stream
is valid and previously created, and pos
is a number larger than 0 and less than or equal to the stream’s size:
stream.Seek(pos, SeekOrigin.Begin);
// Write to Azure Blob Storage
BlobClient blobClient = blobContainerClient.GetBlobClient("MyBlob1");
await blobClient.UploadAsync(stream, true);
If this is run, the code will deadlock while awaiting. The Tasks
view in Visual Studio shows multiple tasks running:
Upon analyzing, each task N is waiting for task N-1, with the exception of:
- 36 (waiting on 161)
- 141 (waiting on 173)
- 168 (only scheduled, and waiting to run)
The call stack, while breaking into during the stall, is below:
Using try
/catch
around the async call doesn’t result in anything throwing.
Should the position in the stream be 0, the call completes as expected.
Environment:
- Name and version of the Library package used:
Azure.Storage.Blobs 12.4.4
- Hosting platform or OS and .NET runtime version (
dotnet --info
output for .NET Core projects):Windows 10 .NET Core 3.1.0
- IDE and version :
Visual Studio 16.5.0 Preview 2
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (12 by maintainers)
Top Results From Across the Web
c# - How to set overwrite in Azure BlobClient when using ...
To perform a partial update of the content of a block blob, use the Azure.Storage.Blobs.Specialized.BlockBlobClient.StageBlock(System.String, ...
Read more >BlobClient.UploadAsync Method (Azure.Storage.Blobs)
The UploadAsync(Stream, BlobUploadOptions, CancellationToken) operation overwrites the contents of the blob, creating a new block blob if none exists.
Read more >Managing concurrency in Blob storage - Azure
Learn how to manage multiple writers to a blob by implementing either optimistic or pessimistic concurrency in your application.
Read more >Class BlobClient | Azure SDK for .NET
Stream content. A System.IO.Stream containing the content to upload. System.Boolean overwrite. Whether the upload should overwrite any existing blobs.
Read more >Uploading Blobs with the V12 Storage SDK
I have been working on updating lots of code from the V11 SDK to V12. ... Uploading a readable stream into blob storage...
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 Free
Top 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
@kasobol-msft had found the source of the issue already, it’s because https://github.com/Azure/azure-sdk-for-net/blob/9118e1d66bee5db546c93a01669c9d66e57a69f9/sdk/storage/Azure.Storage.Blobs/src/BlockBlobClient.cs#L723 doesn’t take Position into account when setting a Content-Lenght header value. Fixing math there and in similar spots would fix the bug.
Hi, please provide reproduction of the problem you are running into using 12.10.0 with as much details as possible so we can resolve it.
Then we can determine if we need to reopen this issue or open a different one.