Http connection freezes when request's content-length exceeds real content length
Question: I have a very basic python script that does HTTP connection.

    
    
    import socket
    
    def main():
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        host = "192.168.56.21"
        s.connect((host, 80))
        msg = """GET /lol /HTTP1.1
    Content-Length: 10    
    
    %s""" % ("*" * 9)
        s.send(msg)
        print msg
        print s.recv(1000)
    
    if __name__ == "__main__":
        main()
    

As you can see, Content-Length header exceeds real content length. When I run
this script, it freezes for 5 mins, and after that I got record in apache log
that request took 5min to execute and got HTTP 400 response.

    
    
    192.168.56.21 - - [01/Apr/2011:15:07:52 +0300] "GET /lol /HTTP1.1" 400 358 "-" "-" 47 531 300011809
    

I am ok with that, but what I do not understand is why apache freezes for 5
min and keeps connection open during that time.

    
    
    apache2   3947 www-data   19u  IPv6  17165       TCP 192.168.56.21:www->192.168.56.21:53112 (ESTABLISHED)
    python2.6 4636   meuser    3u  IPv4  17164       TCP 192.168.56.21:53112->192.168.56.21:www (ESTABLISHED)
    

I assume that apache waits for amount of bytes specified in Content-Length
until some timeout happens and it throws 400 Bad Request.

I tried it against production sites and obviously I got response immediately.

Can someone explain what is going on here on TCP level and what I am missing
apache configuration - I want to get rid of such 5 min waiting.


Answer: OK, it is Timeout directive in apache conf.
<http://httpd.apache.org/docs/2.2/mod/core.html#timeout>

