Feersum icon indicating copy to clipboard operation
Feersum copied to clipboard

psgi.input being undef causes exceptions elsewhere

Open hoytech opened this issue 8 years ago • 6 comments

In the docs it says

Feersum currently passes undef for psgi.input when there is no body to avoid unnecessary work.

Which makes sense, except it causes HTTP::Entity::Parser to throw an exception:

Can't call method "seek" on an undefined value at /usr/local/share/perl/5.22.1/HTTP/Entity/Parser.pm line 71.

I opened an issue there too: https://github.com/kazeburo/HTTP-Entity-Parser/issues/6

I'm not exactly clear on the PSGI spec's take on this, but it seems to say it must be an IO::Handle-like object?

Thanks,

Doug

hoytech avatar Dec 02 '16 22:12 hoytech

Just to be clear, I am seeing this when I issue a POST request with an empty body (admittedly somewhat of an edge case.

Here is a test-case:

use Feersum;
use AnyEvent;
use Plack::Request;

my $socket = IO::Socket::INET->new(Listen => 5, Proto => 'tcp', LocalPort => 9999, ReuseAddr => 1, Blocking => 0) || die "unable to listen: $!";

my $f = Feersum->endjinn;
$f->use_socket($socket);

$f->psgi_request_handler(sub {
    my $env = shift;
    my $req = Plack::Request->new($env);
    $req->parameters;
    return [200, [], []];
});

AE::cv->recv;

When it's running, hit it with curl:

curl http://localhost:9999 -d ''

And you'll see the error:

(in cleanup) DIED: Can't call method "seek" on an undefined value at /usr/local/share/perl/5.22.1/HTTP/Entity/Parser.pm line 71.

hoytech avatar Dec 03 '16 02:12 hoytech

Thanks for the report. Try commenting out lines 1579 and 1582 in Feersum.xs and see if it works for you?

audreyt avatar Dec 03 '16 06:12 audreyt

Thanks! Yes that fixes it (you have to comment out 1583 and 1585 as well so it compiles).

I guess this adds some overhead to GET requests since even then it will create an empty stream. I'm not sure if that's important?

hoytech avatar Dec 03 '16 23:12 hoytech

This change caused the tests to fail in the latest version.

However, with HTTP::Entity::Parser 0.20, this problem no longer happens and the test script above works without issue.

Would it be appropriate to revert these changes, so that Feersum can be installed without failing the graceful shutdown unit test? And perhaps mandate HTTP::Entity::Parser 0.20 as a dependency?

I can send a PR, if the solution works for you :)

ltriant avatar Sep 21 '18 06:09 ltriant

That works, please send the PR and looking forward to a new release with your contribution.

audreyt avatar Sep 21 '18 11:09 audreyt

Thanks @audreyt :)

The remaining test failures seem to only affect the BSDs... If I can diagnose the issue, I'll send another PR.

ltriant avatar Sep 24 '18 00:09 ltriant