'What can cause an async webapi endpoint to act synchronously?

I am creating async api endpoints in DNN (Formerly DotNetNuke).

It is an open source CMS and the source code is here: https://github.com/dnnsoftware/Dnn.Platform It's mainly a webforms application but it supports webapi and MVC too.

Here is the code I have:

[HttpGet]
[AllowAnonymous]
public async Task<IHttpActionResult> TestAsync()
{
    await Task.Delay(2000);
    return this.Ok(new { message = "Hello from async." });
}

[HttpGet]
[AllowAnonymous]
public IHttpActionResult TestSync()
{
    Thread.Sleep(2000);
    return this Ok(new { message = "Hello from sync." });
}

When I do load testing comparing the same method with and without async I get about the same results and it looks like even though the async endpoints work fine, they do not behave async.

If I run the very same endpoints and load tests in a new web application project I get about triple the throughput on the async endpoint vs the normal one.

My question is, what could make this behave non-async in DNN ?

It am putting some links here to what I have looked at in case someone has a clue on what could be the issue.

Looks like default.aspx is setup with async although I guess the webapi pipeline does not depend on default.aspx https://github.com/dnnsoftware/Dnn.Platform/blob/develop/DNN%20Platform/Website/Default.aspx

My controller class inherits from DnnApiController https://github.com/dnnsoftware/Dnn.Platform/blob/develop/DNN%20Platform/DotNetNuke.Web/Api/DnnApiController.cs

Dependency injection is used to find all the controllers that implement DnnApiController https://github.com/dnnsoftware/Dnn.Platform/blob/develop/DNN%20Platform/DotNetNuke.Web/Api/DnnApiController.cs

Routes are registered this way: https://github.com/dnnsoftware/Dnn.Platform/blob/9f83285a15d23203cbaad72d62add864ab5b8c7f/DNN%20Platform/DotNetNuke.Web/Api/Internal/ServicesRoutingManager.cs

I am unsure how this pipeline works and if maybe I missed some obvious entry point that simply needs to be made async or what. Any help is welcome.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source