1

I have a REST service in a self hosted ASP.Net WebApi application (Console).

Some clients poll the server in specific intervals to fetch new data. In general all is working fine.

The problem is, that the server stops responding to requests after some random duration (~30mins - 2.5 hours). All client requests start to time out.

The weird thing is, the server doesn't seem to receive the requests anymore as no controller method is invoked anymore). Server didn't throw any exceptions and the console app is still responsive. So I can only suppose there is a problem, before the request reaches the API controller.

In the debugger everything seems fine.

How can I diagnose such an issue?

What else can I try to fix the described behavior?

Notes:

  • Tested on multiple systems
  • .Net 4.5.1
  • Asp.Net WebApi 5.1.2
paiden
  • 887
  • 7
  • 15
  • 1
    I'm actually having the same issue, web api works and then at some random point it stops receiving my reuqests. did you come to solve this? Altough mine is not self hosted.. – Mattias May 13 '15 at 14:34
  • 1
    Also happened in IIS hosted project. In my case, the problem seems to be async related. In some cases the client closes the connection before the server has finished processing it. This sometimes causes the running task to be kept alive forever/a long time.... I'm not sure why, for now. But I saw the amount of waiting tasks increase over time (VS Tasks Window). I will investigate the issue further and update/answer the question (may take some time as I'm soon on vacation for 4 weeks) – paiden May 15 '15 at 07:46

2 Answers2

0

I have found the issue, the reason this is happening is because of connection leaks. If you are sending requests and aren't closing them correctly, either after the request is finished, or within an exception, the amount of open connections will eventuelly reach it's max value. Either you change the max amount of open connections in the connectionstring or(the prefered way) make sure your code is handling the closing part:

SqlConnection myConnection = new SqlConnection(ConnectionString);
try
{
 conn.Open();
 someCall (myConnection);
}
finally
{
 myConnection.Close();                
}   

Credit goes to How can I solve a connection pool problem between ASP.NET and SQL Server? Where you can read more about this.

Community
  • 1
  • 1
Mattias
  • 2,929
  • 5
  • 29
  • 46
0

In my case, the issue was caused by never ending tasks. Due a misusage of the ReactiveExtensions Api, I randomly created never ending tasks. It seems, at some point the task scheduler simply couldn't handle them anymore, although I'm not completely sure about that.

Thing learned: It seems, by doing bad things in your app code (too many tasks, SQL connections ...) you can kill the WebApi infrastructure, so that it doesn't handle requests - at any level - anymore.

paiden
  • 887
  • 7
  • 15