Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Twiggy CPAN distribution.

Report information
The Basics
Id: 78177
Status: open
Priority: 0/
Queue: Twiggy

People
Owner: Nobody in particular
Requestors: khedin [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.1020
Fixed in: (no value)



Hello, I'm getting started with Twiggy and have already found a way to crash it. My app is like this (in fact, slightly modified example from PSGI man page regarding delayed response, see: http://search.cpan.org/~miyagawa/PSGI-1.10/PSGI.pod#Delayed_Response_and_Streaming_Body ): #!/usr/bin/perl -w use strict; use AnyEvent; my $app = sub { my $env = shift; return sub { my $responder = shift; my $writer = $responder->([200, [ 'Content-Type' => 'text/plain' ]]); # set up timer my $tm; my $stage; $tm = AnyEvent->timer( after => 1, interval => 1, cb => sub { if (++$stage<=5) { # print 1..5 $writer->write($stage); } else { # stop here $writer->close; $tm = undef; }; }); }; }; So we send 12345 to user in 5 seconds. Now, I want to simulate the user falling off and so I ran % perl -we 'alarm 1; use LWP::UserAgent; \ my $ag = LWP::UserAgent->new; $ag->get("http://127.1:5000/");' And suddenly, on my Ubuntu Twiggy died with error message AnyEvent::Handle uncaught error: Broken pipe at /home/kuvarin/lib/perl/5.10.1/Twiggy/Server.pm line 601 On FreeBSD I got a warning message instead. The error is 100% reproducible with Twiggy 0.1020 on both machines. As I understand by reading AnyEvent::Handle's source, it can be avoided by setting an on_error handler in handle's constructor. I'd like to do more research here, and would appreciate any help. Thanks for your time, Konstantin S. Uvarin
From: vitaliy.tokarev [...] gmail.com
Show quoted text
> As I understand by reading AnyEvent::Handle's source, it can be > avoided > by setting an on_error handler in handle's constructor.
You are right. Fast fix in your example: my $tm; $writer-{handle}->on_error(sub { undef $tm; }); $tm = AE::timer .... I've attached patch for Twiggy::Server with same functionality, just remove AE::log line in it or leave as is. And also fix one line in timer callback: $tm = AE::timer 1, 1, sub { if ($responder && ++$stage <= 5) { # check if $responder is valid $writer->write($stage); } else { $writer->close; undef $tm; } };
Subject: Twiggy_Server_delay_01.diff
--- /home/tvv/.staticperl-5.16.2/lib/Twiggy/Server.pm.orig +++ /home/tvv/.staticperl-5.16.2/lib/Twiggy/Server.pm @@ -329,6 +329,12 @@ my $writer = Twiggy::Writer->new($sock, $self->{exit_guard}); my $buf = $self->_format_headers($status, $headers); + + $writer->{handle}->on_error(sub { + AE::log error => "handle error: $!"; + undef $res; + }); + $writer->write($$buf); return $writer;