2

I'm storing some large files in a Blog Storage Container.

Later, using a WebJob (also in Azure), I read from each of these blobs using CloudBlockBlob.OpenRead() that gives me a Stream.

I open the stream and read from it. The problem is that when the file is larger than 25 MB aprox., after some time reading OK, it throws this exception (during a read):

Unhandled Exception: System.Net.Http.HttpRequestException: Error while copying content to a stream. ---> System.ObjectDisposedException: Cannot access a closed Stream. at System.IO.__Error.StreamIsClosed() at System.IO.MemoryStream.get_Position() at System.Net.Http.StreamToStreamCopy.StartAsync()

It seems that the file is closed on the other side!

Why does this happen? Is there a timeout? How can I handle this situation?

SuperJMN
  • 13,110
  • 16
  • 86
  • 185

2 Answers2

3

Depending on your connection speed, your response may be timing out. This would support your statement that it is for files of about 25MB. Increase the ServerTimeout and/or MaximumExecutionTime using BlobRequestOptions to resolve.

Murray Foxcroft
  • 12,785
  • 7
  • 58
  • 86
  • The thing is that I'm not downloading the file, but opening a stream from it using cloudBlobBlock.OpenRead(). This is a by requirement. – SuperJMN Jul 26 '16 at 09:19
  • 1
    Have you tried setting BlobRequestOptions ServerTimeout and Maximum execution time? https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storage.blob.blobrequestoptions_members(v=azure.10).aspx – Murray Foxcroft Jul 26 '16 at 09:27
  • It works! using OpenRead with these options: return block.OpenRead(null, new BlobRequestOptions() { ServerTimeout = TimeSpan.MaxValue, RetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(5), 4), MaximumExecutionTime = TimeSpan.FromHours(3) }); – SuperJMN Jul 26 '16 at 10:16
0

I've invoked the OpenRead() method with these options and it seems it no longer times out!

return block.OpenRead(null, new BlobRequestOptions()
            {
                ServerTimeout = TimeSpan.MaxValue,
                RetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(5), 4),                
                MaximumExecutionTime = TimeSpan.FromHours(3)
            });
SuperJMN
  • 13,110
  • 16
  • 86
  • 185