1

Closed

HttpRequest.ReadSocket method spinning

description

Hi, First of all, thank you very much for your effort and great work on this toolkit. I am using the latest released source (23728) and have a WebServer using HttpService (non-MF) with an ajax type method that I'm calling from within a timer in IE7 using jQuery, which recurs at about 2 second rate. After about 1000 to 2000 such requests, the server appears to melt down with many "Client Worker Process" threads spinning inside HttpRequest.ReadSocket(). - In this case spinning with the first while(true) loop in the method, at line 404 -- if(avail == 0) { continue (with a commented // Thread.Sleep(10);
 
I suspect that the connection went bad, or IE7 got sick and the socket.Poll() method did not detect the problem, so the thread kept spinning in a tight loop - with no mechanism to see the problem. I'm wondering if anyone else has seen this and has any suggestions for a fix or hack? Was wondering about a DateTime.Now type timeout on the loop that would either throw an exception or similar? I do believe that the client or network is somehow causing the original problem, but I see this as a robustness issue with the server.
 
I believe that I've seen a similar behavior on the MF version of my server as well, but am not sure.
 
Again, thanks for the great work and thanks in advance for comments or advice.
 
Don
Closed Nov 8, 2010 at 12:41 PM by interactive

comments

donschwemle wrote May 5, 2009 at 11:15 PM

After further review, I found a few bugs that make the HttpServer non-thread safe. My application was making multiple ajax callbacks to the server and the server was dying when two requests came in simultaneously. Specifically, the line client -= listenSocket.Accept) was clobbering the previously accepted socket of the previous request. The solution is ralatively simple - the various calls that are passing the client socket should not have used the keywork "ref" since the socket is already a reference object and the called methods do not need to "re-create" the socket. Passing it by ref caused the Accept() method to overwrite the "reference to reference" to the previous socket.

private void CreateWorkerProcess(Socket client) method and all calls to it should have "ref" removed.
public ProcessClientRequest(Socket Client, IHttpHandler Handler, HttpServer Server) and calls to it should have "ref" removed.

Again, thanks for the GREAT toolkit - I really appreciate your efforts! Don

wrote Nov 8, 2010 at 12:41 PM

Resolved with changeset 59004.

wrote Feb 14, 2013 at 8:10 PM

wrote May 16, 2013 at 9:49 AM