This project is read-only.

Client keeps waiting until the socket is closed

Topics: blog
Mar 3, 2011 at 3:10 AM


I'm using the C# web server for listening to http equests on my server. Here is the problem:

Client sends a GET request or a POST request

Server sends the response back

Client keeps waiting for the response and doesn't receive unless the server socket is closed.

Here is a sample request/response:


User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20110218 Firefox/3.6.14 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive

Connection: Keep-Alive
Keep-Alive: timeout=5, max=100
Date: Thu, 03 Mar 2011 03:00:53 GMT
Server: C# Webserver
Content-Type: text/html

The timeout is defined by:


private int _keepAliveTimeout

in HttpContext class.

The client waits for exactly the time defined in keepAliveTimeout. Any clues on why would that happen? I've tried with GET/POST with my client as well as with standard Firefox browser as client as well.

Here's how I send the response:


        protected void SendResponse(RequestContext context, HttpStatusCode status)
            context.Response.Status = status;
            var generator = new ResponseWriter();
            generator.Send(context.HttpContext, context.Response);
            if (context.Request.Connection != null &&
                context.Request.Connection.Type == ConnectionType.Close)
            Console.WriteLine("Sending Response:" + context.Response.Status);
            generator = null;

from a custom module which returns ProcessingResult.Abort; from "Process" method after the response is sent.

Is there anything I'm missing?



Mar 3, 2011 at 7:16 AM

I don't see a body or a content-length header. If you got no body, set content-length to zero (it's a bug if it's not being sent automatically, but you can try to add it t see if that's the case).

Mar 4, 2011 at 3:40 AM
Edited Mar 4, 2011 at 3:47 AM



That did the trick for sure (client received immediate response). But just after that the server dies with error: "An unhandled exception of type 'System.ExecutionEngineException' occurred in Unknown Module." . No stack trace, no other exception details. I'm not sure which module is causing it. Any clues?



Mar 4, 2011 at 6:11 AM
Edited Mar 4, 2011 at 6:12 AM

I have got it now and then in the past. Try upgrading your .Net framework since something is causing a bug in it. Since it's .net itself that crashes you can't get a stack trace and I never found out why I got it (and therefore I do not know how I got rid of it).


Not very helpful, i know.