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] BlobClient.UploadAsync(Stream content, bool overwrite) deadlocks if the stream is not rewinded

See original GitHub issue

Consider 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: image

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: image

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:closed
  • Created 3 years ago
  • Comments:14 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
pakrymcommented, Aug 17, 2020

@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.

0reactions
amnguyecommented, Dec 21, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

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