I have an app that's sending 500 HTTP requests asynchronously. All requests processed after 15 seconds fail because of the timeout on the HTTP Client, even when the requested endpoint already returned a 200 OK.
The code is very straight-forward. Here we take a chunk of requests (500), and execute them asynchronously. It should be noted that the function below is an Azure function running on the consumption-based plan.
public async Task RunBatch(List<Request> requests)
{
if (requests != null && requests .Count > 0)
{
var tasks = new Task[requests.Count];
var i = 0;
foreach (var request in requests)
{
var request = new HttpRequestMessage(HttpMethod.Post, new Uri(request.Url));
request.Content = new StringContent(request.BodyString, Encoding.UTF8, "application/json");
tasks[i] = _httpClient.SendAsync(request);
i++;
}
await Task.WhenAll(tasks);
}
}
The following code exists in my constructor
_httpClient = new HttpClient();
_httpClient.Timeout = new TimeSpan(0, 0, 15); // 15 seconds
Here are logs from Azure.
I'd like each request to have a timeout of 15 seconds. However, I need it to give me an accurate response code whenever my server gets around to processing the awaited request. Is this possible?
I should note: with a higher Http timeout (1 min), all requests succeed.

