Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Dev

HTTP engine closing socket on header failure

 

 

Catalyst dev RSS feed   Index | Next | Previous | View Threaded


ton.voon at altinity

Apr 3, 2008, 2:49 PM

Post #1 of 7 (395 views)
Permalink
HTTP engine closing socket on header failure

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.

Ton

http://www.altinity.com
UK: +44 (0)870 787 9243
US: +1 866 879 9184
Fax: +44 (0)845 280 1725
Skype: tonvoon
Attachments: Catalyst-Engine-HTTP_retry_on_ewouldblock.patch (0.79 KB)


jon at jrock

Apr 3, 2008, 11:55 PM

Post #2 of 7 (379 views)
Permalink
Re: HTTP engine closing socket on header failure [In reply to]

* On Thu, Apr 03 2008, 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.

Can you include a test for this also?

--
print just => another => perl => hacker => if $,=$"

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev[at]lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


andy at hybridized

Apr 4, 2008, 9:08 AM

Post #3 of 7 (378 views)
Permalink
Re: HTTP engine closing socket on header failure [In reply to]

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.

-Andy


_______________________________________________
Catalyst-dev mailing list
Catalyst-dev[at]lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


ton.voon at altinity

Apr 4, 2008, 12:22 PM

Post #4 of 7 (375 views)
Permalink
Re: HTTP engine closing socket on header failure [In reply to]

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


_______________________________________________
Catalyst-dev mailing list
Catalyst-dev[at]lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


andy at hybridized

Apr 4, 2008, 12:35 PM

Post #5 of 7 (375 views)
Permalink
Re: HTTP engine closing socket on header failure [In reply to]

On Apr 4, 2008, at 3:22 PM, Ton Voon wrote:
>
> 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

Hmm, I don't want to break RESTART though.

You may be interested in a new engine I'm about to release hopefully
later today that implements pre-forking and scales a lot better than
the built-in HTTP engine.

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev[at]lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


ton.voon at altinity

Apr 4, 2008, 1:04 PM

Post #6 of 7 (374 views)
Permalink
Re: HTTP engine closing socket on header failure [In reply to]

On 4 Apr 2008, at 20:35, Andy Grundman wrote:
> Hmm, I don't want to break RESTART though.

Actually, I just thought maybe you could use the $options->{restart}
flag to decide whether to fork immediately or not. Would you go for
that?

> You may be interested in a new engine I'm about to release hopefully
> later today that implements pre-forking and scales a lot better than
> the built-in HTTP engine.

That sounds very interesting. Would be happy to help test and develop.

Ton


_______________________________________________
Catalyst-dev mailing list
Catalyst-dev[at]lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


andy at hybridized

Apr 4, 2008, 1:12 PM

Post #7 of 7 (373 views)
Permalink
Re: HTTP engine closing socket on header failure [In reply to]

On Apr 4, 2008, at 4:04 PM, Ton Voon wrote:
>
> On 4 Apr 2008, at 20:35, Andy Grundman wrote:
>> Hmm, I don't want to break RESTART though.
>
> Actually, I just thought maybe you could use the $options->{restart}
> flag to decide whether to fork immediately or not. Would you go for
> that?

Sure, that sounds good.

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev[at]lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev

Catalyst dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.