Fwd: perlbal fails on OSX

Chuck Remes cremes.devlist at mac.com
Sat Apr 14 17:53:26 UTC 2007


Forwarded to the list in case this bites anyone else... this patch  
works and now all tests pass.

cr

Begin forwarded message:

> From: Radu Greab <radu at yx.ro>
> Date: April 13, 2007 2:46:38 PM CDT
> To: cremes.devlist at mac.com
> Subject: Re: perlbal fails on OSX
>
>
> Hi,
>
>> The last packet contains a header where the Content-Length is set to
>> 31000 bytes. This packet causes the hang. The following code from
>> Test.pm#resp_from_sock goes into an infinite loop:
>>
>>      my $cl = $resp->header('Content-Length');
>>      if (defined $cl && $cl > 0) {
>>          my $content = '';
>>          while (($cl -= read($sock, $content, $cl)) > 0) {
>>              # assume an error means connection closed
>>              last if $!;
>>              # don't do anything, the loop is it
>>          }
>>          $resp->content($content);
>>      }
>>
>> It sits in that while loop forever because there is no body attached
>> (it's just a HEAD request) yet the Content-Length > 0.
>
> The above code assumes that the loop will be left when a reading  
> from a
> closed socket is tried (errno will be set). May I ask you to try the
> change below, which will make the loop finish when EOF is read from
> the socket?
>
>
> === lib/Perlbal/Test.pm
> ==================================================================
> --- lib/Perlbal/Test.pm	(revision 75559)
> +++ lib/Perlbal/Test.pm	(local)
> @@ -189,9 +189,9 @@
>      my $cl = $resp->header('Content-Length');
>      if (defined $cl && $cl > 0) {
>          my $content = '';
> -        while (($cl -= read($sock, $content, $cl)) > 0) {
> -            # assume an error means connection closed
> -            last if $!;
> +        my $rv;
> +        while (($rv = read($sock, $content, $cl)) &&
> +               ($cl -= $rv) > 0) {
>              # don't do anything, the loop is it
>          }
>          $resp->content($content);
>



More information about the perlbal mailing list