Reputation: 3035
I wonder why I cannot set a timeout. If I cannot submit a message to a queue within a few seconds I rather cancel the attempt and do an exponential back off.
QueueRequestOptions queueRequestOptions = new QueueRequestOptions();
queueRequestOptions.ServerTimeout = TimeSpan.FromSeconds(3);
OperationContext operationContext = new OperationContext();
OperationContext.DefaultLogLevel = Microsoft.WindowsAzure.Storage.LogLevel.Verbose;
operationContext.ClientRequestID = correlationId;
operationContext.CustomUserAgent = "myCallerId";
await queue.AddMessageAsync(message, null, null, queueRequestOptions, operationContext);
Not exactly pretty but neither fulfilling its job :( If I set a wrong dns name for the storage account, the request does not time out after 3 seconds as expected.
Given the fact that there is a HttpClient behind the scenes it should be possible to set a timeout for http calls.
CloudQueueClient cloudQueueClient = _cloudStorageAccount.CreateCloudQueueClient();
cloudQueueClient.DefaultRequestOptions.ServerTimeout = TimeSpan.FromSeconds(3);
That was not working either.
In the meantime I had a look at the source code of the Azure Storage SDK:
namespace Microsoft.WindowsAzure.Storage.Shared.Protocol
{
internal static class HttpClientFactory
{
[CompilerGenerated]
[Serializable]
private sealed class <>c
{
public static readonly HttpClientFactory.<>c <>9 = new HttpClientFactory.<>c();
internal HttpClient cctor>b__3_0()
{
HttpClient expr_0B = new HttpClient(StorageAuthenticationHttpHandler.Instance, false);
expr_0B.get_DefaultRequestHeaders().set_ExpectContinue(new bool?(false));
expr_0B.get_DefaultRequestHeaders().get_UserAgent().Add(new ProductInfoHeaderValue("Azure-Storage", "8.5.0"));
expr_0B.get_DefaultRequestHeaders().get_UserAgent().Add(new ProductInfoHeaderValue(Constants.HeaderConstants.UserAgentComment));
expr_0B.get_DefaultRequestHeaders().TryAddWithoutValidation("x-ms-version", "2017-04-17");
expr_0B.set_Timeout(Timeout.InfiniteTimeSpan);
return expr_0B;
}
}
private static Lazy<HttpClient> instance = new Lazy<HttpClient>(new Func<HttpClient>(HttpClientFactory.<>c.<>9.<.cctor>b__3_0));
public static HttpClient Instance
{
get
{
return HttpClientFactory.instance.get_Value();
}
}
}
}
So the timeout is being set. To Infinite. And I couldn't find any place where the Timeout is being set to a different value. Can it be true? -.-
Upvotes: 0
Views: 1645
Reputation: 51
Try setting queueRequestOptions.MaximumExecutionTime. That is the client-side timeout. The server timeout is passed to the service and is not enforced on the client.
See https://learn.microsoft.com/en-us/azure/architecture/best-practices/retry-service-specific#azure-storage-retry-guidelines for more details.
Upvotes: 1