[Catalyst-dev] HTTP engine closing socket on header failure

Ton Voon ton.voon at altinity.com
Fri Apr 4 20:22:02 BST 2008


On 4 Apr 2008, at 17:08, Andy Grundman wrote:
>
> On Apr 3, 2008, at 5:49 PM, Ton Voon wrote:
>> Hi!
>>
>> We hit a problem with the HTTP development engine where a  
>> connection would come in without any headers and the remote socket  
>> wasn't being closed correctly.
>>
>> This patch to Catalyst::Engine::HTTP closes the Remote connection  
>> and also prints debug statements around the sysread.
>
> Thanks.  You're right that STDIN is set to non-blocking before  
> _read_headers is called the second time, so it needs to support non- 
> blocking mode.
>
> Your patch looks sane, I've committed a slightly modified version.   
> A test case would be nice but I realize it's a bit hard in this  
> case.  I tested manually and saw the connection bug with the old  
> code, and the patch definitely fixes it.


Great - I'm glad you found it useful.

Actually, we did a bit more digging and found another limitation. The  
symptoms we were seeing was that the dev server was hanging on a  
read(), which is at the sysread() call in _read_headers. We don't  
understand why this happens, but since the _read_headers is done by  
the main myapp_server.pl process before a fork, this means that all  
subsequent connections hang until the sysread() times out (or the  
connection is closed - not sure which).

We've amended the code in C::E::HTTP within the accept() loop so that  
it forks immediately, instead of trying to read the headers first.  
This means the connection that was causing the problem (which is  
pretty random, about 5 times a day) hangs, but all other requests work  
fine thus isolating the issue.

The downside to this is that the RESTART method is not available  
anymore. Would you be interested in this patch?

Ton

http://www.altinity.com
UK: +44 (0)870 787 9243
US: +1 866 879 9184
Fax: +44 (0)845 280 1725
Skype: tonvoon




More information about the Catalyst-dev mailing list