Search code examples
c#.netasp.net-mvcasp.net-coredependency-injection

Requests to ASP.NET Core API are stuck in pending state


I am working on ASP.NET Core MVC project and I have some JS code that calls my API endpoints to get some extra data.

So I am doing some AJAX requests. And while some are successful, others seem to be stuck in pending state (state from browser's devtools), please see attached picture:

enter image description here

You can see some XHR requests are successful (and I can hit breakpionts in those endpoints, debug, etc.).

And ones below are stuck in pending state ("oczekuje" is pending). I can not hit breakpoints in those endpoints, but I can hit and debug middleware, so it gets stuck somewhere in HTTP request pipeline I guess.

And I guess my question here is looking for any clues, as i am not sure where else I could look.

EDIT

To add more context, I am migrating from .NET Framework 4.5 and there it runs correctly. Here are the sizes of the requests:

enter image description here


Solution

  • As I guessed, it was something internal to C# code, some recursion of some sort or dead lock.

    So I followed MS documentation on how to Debug a deadlock in .NET Core :

    • firstly installed tools dotnet-dump and dotnet-trace with dotnet tool install command

    • then I run the app, run the command dotnet-trace ps to get process ID of the running app and then dotnet-dump collect -p 8280 (with ID of found process)

    • this will write dump to file - just run dotnet-dump analyze path-to-file to analyze the dump

    This will enter interactive mode, where clrstack -all will output stacks of all threads.

    As I analyzed, I noticed that ServiceCollection tried to resolve some circular dependency, as I have endless stack on one thread such as below:

    enter image description here

    So I narrowed the problem and found problematic dependency and fixed DI registration and usage.

    That solved the issue.