I have code using Azure Storage Library that goes like this:
CloudBlobContainer container = obtainContainer();
var blobList = container.ListBlobs(options:OptionsWithLinearRetry);
foreach (var blobItem in blobList) // << exception happens here sometimes
{
//process item
}
and it works okay most of the time. But sometimes something goes wrong with the network and then I get:
Microsoft.WindowsAzure.Storage.StorageException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
and the stack is like this:
// lots of Azure Storage Library stuff here
at Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.<>c__DisplayClass13.<ListBlobs>b__12(IContinuationToken token)
at Microsoft.WindowsAzure.Storage.Core.Util.General.<LazyEnumerable>d__0`1.MoveNext()
// my code with foreach line here
and so it looks like the foreach causes a MoveNext()
call and the latter fails when obtaining the new chunk of data.
Can I somehow cause that MoveNext()
call to be retried? Is there a way to have a "try-catch-retry" logic in foreach loop?