I had a strange, sporadic problem with a simple test application (the Visual Studio console application) that acts as a watchdog for a hosted aspx website (and not an application), sending it simple HTTP requests and response time response times. I have used this for many weeks in the past without this particular problem. At seemingly random times during the day, my HTTP requests start with the error above. They seem to time out, as requests that fail take 60 seconds. After a period of consistent errors, as described above (random time periods from a few minutes to 90 minutes in one case), errors stop and HTTP responses begin to return without errors at normal speed (usually about 0.25 s). Watchdog client requests start a very simple database search, only 1-2 lines of code on the server side. This is hosted on shared hosting by Windows hosting.
I can also initiate this behavior on my own by updating any .cs file on my host site, which, among other things, causes the application pool to recycle. Immediately my watchdog application starts counting again with the above error.
This smells like some kind of reworked connection problem, because if I just restart the watchdog application, it works fine and the responses will start to return with a normal delay.
I tried setting request.KeepAlive = false and request.ServicePoint.ConnectionLimit = 1, this did not help.
Another key, I canโt connect to IIS Manager on any of two different sites hosted on this server, which always worked fine. I get โThe primary connection was closedโ while trying to connect through IIS Manager. Everytime. I have not updated any of the sites in a while, so this was not my replacement.
This is an asp.net 4 website on a server running IIS7 with a dedicated application pool in integrated pipeline mode.
Also, if I change the sleeptime variable in the watchdog application for about 30 seconds, the problem will not appear. There's some kind of magic number in the range that I believe in for 10-20 seconds, where if requests are suspended more, they never fail.
I think the fact that the IIS manager cannot connect is good proof that something is wrong on the host side, regardless of my test application, but I wanted to close my databases before opening an incident with support .. .Moreover, just restarting my console application fixes the problem ... at least for a while.
class Program { //make a simple web request and just return the status code static string SendHttpMsg(string url, string postData) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(url)); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; ASCIIEncoding encoding = new ASCIIEncoding(); byte[] byte1 = encoding.GetBytes(postData); request.ContentLength = byte1.Length; //request.KeepAlive = false; //no effect //request.ServicePoint.ConnectionLimit = 1; //no effect Stream requestStream = request.GetRequestStream(); requestStream.Write(byte1, 0, byte1.Length); requestStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); response.Close(); return ((int)response.StatusCode).ToString(); } static void Main(string[] args) { int sleeptime = 5000; string result = ""; while (true) { DateTime start = DateTime.Now; try { //this is a very simple call that results in a very simple, fast query in the database result = SendHttpMsg("http://example.com/somepage.aspx", "command=test"); } catch (Exception ex) { //fancy exception handling here, removed } DateTime end = DateTime.Now; TimeSpan calltime = end - start; Console.WriteLine(end.ToString() + ", " + calltime.TotalSeconds.ToString("F") + " seconds " + result); Thread.Sleep(sleeptime); } } }