Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long write + client disconnect = unhandled exception in callback #36

Open
dallaylaen opened this issue Jun 26, 2013 · 0 comments
Open

Comments

@dallaylaen
Copy link

Hello,

This is a duplicate of issue in RT https://rt.cpan.org/Public/Bug/Display.html?id=78177

I've been testing Twiggy with long-lasting queries and found out that it can be crashed/confused (depending on OS and event loop engine used) by suddenly closing connection on the client side.

Here's a sample PSGI app that reliably reproduces this situation. It outputs 12345 in 5 seconds:

#!/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;
            };
        });
    };
};

After running twiggy 12345.psgi, the event can be triggered by this one-liner:

perl -we 'alarm 1; use LWP::UserAgent; my $ag = LWP::UserAgent->new; $ag->get("http://127.0.0.1:5000/");

Here's error message from my Linux box:

EV: error in callback (ignoring): AnyEvent::Handle uncaught error: Broken pipe at lib/Twiggy/Server.pm line 601

It looks like the problem can be solved by setting on_error on Twiggy::Writer's handle. However, I'm not sure where to set it (in constructor maybe?) so I'm not proposing a patch right away.

ISim pushed a commit to ISim/Twiggy that referenced this issue Apr 16, 2015
* installing on_error handler
* ignoring $writer->write() when handler is closed
* added test  t/anyevent_closed_streaming_async.t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant