Uploading async to Azure Blob Storage never returns Uploading async to Azure Blob Storage never returns azure azure

Uploading async to Azure Blob Storage never returns


The error is almost certainly further up your call stack, where some method is blocking on the returned task (e.g., Task<T>.Result, Task.Wait, etc.). This will deadlock if the thread being blocked is required for the task to complete.

I explain this situation in full on my blog, but the gist of it is this:

  • await by default will capture a "context" and use that to resume the async method.
  • If this code is executed in an ASP.NET request context, this "context" is an ASP.NET SynchronizationContext; if this code is executed in a UI thread, this "context" is a UI SynchronizationContext.
  • Both the ASP.NET SynchronizationContext and UI SynchronizationContext only allow one thread in them at a time.

Thus, when the calling code blocks on the returned Task, it is holding a thread within that context, preventing the Task from completing.