Not starting task in DelegatingHandler causes request to hang
description
A simple but possibly common coding error caused a difficult to diagnose issue as follows:
public class BadMessageHandler : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
return new Task<HttpResponseMessage>(() => new HttpResponseMessage(HttpStatusCode.NotAcceptable));
}
}
Because the task isn't started, the request appears to hang in fiddler with no error. Recommend that you check for tasks returned in HttpMessageHandlerChannel that are in WaitingForActivation state and take some action to help the developer.
The above bad code should have been:
return Task<HttpResponseMessage>.Factory.StartNew(() => new HttpResponseMessage(HttpStatusCode.NotAcceptable));