Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] BlobClient.UploadAsync never completes #12811

Closed
pekspro opened this issue Jun 16, 2020 · 7 comments
Closed

[BUG] BlobClient.UploadAsync never completes #12811

pekspro opened this issue Jun 16, 2020 · 7 comments
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Storage Storage Service (Queues, Blobs, Files)

Comments

@pekspro
Copy link
Contributor

pekspro commented Jun 16, 2020

Describe the bug
BlobClient.UploadAsync never completes if it is called with a Stream where Position isn't 0.

Expected behavior
If should write the stream from the current position, or throw an Exception.

Actual behavior (include Exception or Stack Trace)
If never completes

To Reproduce
The following code shows the problem:

var CloudBlobClient = new BlobContainerClient(ConnectionString, "test");

await CloudBlobClient.CreateIfNotExistsAsync();

BlobClient cloudBlockBlob = CloudBlobClient.GetBlobClient("myblob");

MemoryStream stream = new MemoryStream();
await stream.WriteAsync(new byte[15]);
        
// If Position is set to 0 UploadAsync will return.
// stream.Position = 0;
        
await cloudBlockBlob.UploadAsync(stream, overwrite: true);

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): Microsoft.NETCore.App 3.1.5, Windows 10 19.09
  • IDE and version : Visual Studio 16.6.2
@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jun 16, 2020
@jsquire jsquire added Client This issue points to a problem in the data-plane of the library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files) labels Jun 16, 2020
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Jun 16, 2020
@ghost
Copy link

ghost commented Jun 16, 2020

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.

@seanmcc-msft
Copy link
Member

Hi @pekspro, it appears you a mixing V11 and V12 code.

Using only V12 code, I can't repo the issue:

using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Specialized;
using System.IO;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    class Program
    {
        static async Task Main(string[] args)
        {
            string connectionString = "";
            BlobContainerClient container = new BlobContainerClient(connectionString, "mycontainer45");
            try
            {
                await container.CreateAsync();
                BlockBlobClient blockBlobClient = container.GetBlockBlobClient("myblockblob");
                MemoryStream stream = new MemoryStream();
                await stream.WriteAsync(new byte[15]);
                stream.Position = 0;
                await blockBlobClient.UploadAsync(stream);
            }
            finally
            {
                await container.DeleteAsync();
            }

        }
    }
}

I recommend removing the V11 NuGet dependencies from your project.

@seanmcc-msft seanmcc-msft self-assigned this Jun 16, 2020
@seanmcc-msft seanmcc-msft removed Service Attention Workflow: This issue is responsible by Azure service team. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team labels Jun 16, 2020
@ghost ghost added the needs-team-triage Workflow: This issue needs the team to triage. label Jun 16, 2020
@seanmcc-msft seanmcc-msft removed the needs-team-triage Workflow: This issue needs the team to triage. label Jun 16, 2020
@pekspro
Copy link
Contributor Author

pekspro commented Jun 17, 2020

Thanks for a quick reply @seanmcc-msft. I am using version 12.4.4, my csproj looks like this:

<PropertyGroup>
  <OutputType>Exe</OutputType>
  <TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="Azure.Storage.Blobs" Version="12.4.4" />
</ItemGroup>

I get the same problem with your code after this line was removed:

stream.Position = 0;

@seanmcc-msft
Copy link
Member

You need to reset the stream.Position to 0 before upload, this is by design.

@pekspro
Copy link
Contributor Author

pekspro commented Jun 17, 2020

@seanmcc-msft, if that is by design, then UploadAsync should verify this and throw an exception if Position is not 0 in my opinion. Now it never completes and that is just bad.

Also, why does position needs to be 0? Why can not it just read the stream from the current position to the end? This works fine when we are working with ordinary files:

static async Task Main(string[] args)
{
    using MemoryStream stream = new MemoryStream(
        System.Text.ASCIIEncoding.ASCII.GetBytes("Ignore this! Hello world!")
        );

    stream.Position = 13;

    using FileStream fileStream = new FileStream("myfile.txt", FileMode.OpenOrCreate);

    await stream.CopyToAsync(fileStream);
}

I agree that is very rare and I can not say this is important to support. I just think this is strange.

@seanmcc-msft
Copy link
Member

@pekspro, I think that's a good suggestion for UploadAsync() to check the stream position.

Also, why does position needs to be 0? Why can not it just read the stream from the current position to the end?

See #10814 for the discussion around this.

@seanmcc-msft
Copy link
Member

I'm going to close this issue, but please free to continue contributing on #10814.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

No branches or pull requests

3 participants