I'm hosting an application on Azure as a continuous WebJob. The program frequently (around once per second) makes calls to a CosmosDB database by creating a DocumentClient instance (I make use of the DocumentClient function CreateDocumentQuery and a Linq Query on the resultant IEnumerable to retrieve objects from my database). When I run the program locally it behaves as expected without any issues. When I publish the program as an Azure WebJob and run it, my logs indicate that an HttpRequestException is being thrown with the message:
An error occurred while sending the request.
Additionally, I get the following stack trace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task1.get_Result() at Microsoft.Azure.Documents.Linq.DocumentQuery1.d__31.MoveNext() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source) at ... my calling code...
This problem only seems to occur when I make frequent use of the DocumentClient and only on the WebJob side of things. Running an equivalent load locally does not faze my application. Why is this exception occurring in my WebJob? It might be worth noting that this problem occurs with both the S1 and P1V2 App Service tiers.