I'm using HttpClient in the context of a web request to send another web request as follows:
private async Task SendManagerInfoAsync(Uri baseUri, string accessToken, object obj,
string apiPath, HttpMethod httpMethod)
{
string authToken = await GetManagerAuthToken(baseUri, accessToken)
.ConfigureAwait(false);
string url = new Uri(baseUri, apiPath).AbsoluteUri;
var request = new HttpRequestMessage(httpMethod, url)
{
Content = new StringContent(JsonConvert.SerializeObject(obj))
};
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
request.Headers.Add("Authorization", authToken);
// For whatever reason, always throws a TaskCanceledException.
var response = await m_httpClient.SendAsync(request).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
}
The request I'm tracking down is an HTTP PUT. For some reason, this code always throws a TaskCanceledException once it reaches the preset HttpClient.Timeout length, about 30 seconds. However, when I check the recipient of this request, I see that the datastore is always already updated with the information I'd sent within one second of the originating request.
I don't understand why or how the HttpClient instance would throw an exception when the request is actually successful. No cancellation token is being requested. Has anyone ever seen a behavior like this before?
* I tagged this question as related to Akamai because I can only observe this behavior when we flip a switch turning on Akamai services for the server receiving the request.
TaskCanceledException.