Hi all, and mostly John,

I was just browsing through the upcoming Advent code examples when I saw the example for this had a bug. The code will die horribly when a call is made to HEAD rather than get as the output filehandle gets closed. The die is from an uncaught exception on $self->write.

My patch to MyApp::Stream :

sub read_chunk {
  my ($self, $fh, $offset) = @_;
  my $buffer = '';
  aio_read $fh, $offset, 65536, $buffer, 0, sub {
    my $status = shift;
    die "read error[$status]: $!" unless $status >= 0;
    if($status) {
      eval {
        $self->write($buffer);
      };
      if ($@) {
        warn "Cannot write, probably a closed pipe";
      }
      $self->read_chunk($fh, ($offset + 65536));
    } else {
      $self->close;
      aio_close $fh, sub { };
    }
  }
}

So the eval block and the warn, not die as this is not being caught under any other exception handler. Real world, YMMV. Not elegant, but would probably be better for passing in context.

Also I have a full Advent style writeup of the issue Bill brought up recently with explainations and solutions down to making the handle DWIW for for transparent handing over to Catalyst. If that is wanted/needed :)

Neil


---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

Reply via email to