Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix leaking fds + test

  • Loading branch information...
commit 98f79ef7976f60c06d50c7c315b7e9c3210a4524 1 parent c85c527
@bobtfish bobtfish authored
Showing with 67 additions and 0 deletions.
  1. +1 −0  lib/Twiggy/Server.pm
  2. +66 −0 t/anyevent_manyconnections.t
View
1  lib/Twiggy/Server.pm
@@ -354,6 +354,7 @@ sub _write_psgi_response {
if ( eval { $_[0]->recv; 1 } ) {
$self->_write_body($sock, $body)->cb(sub {
shutdown $sock, 1;
+ close $sock;
$self->{exit_guard}->end;
local $@;
eval { $cv->send($_[0]->recv); 1 } or $cv->croak($@);
View
66 t/anyevent_manyconnections.t
@@ -0,0 +1,66 @@
+use strict;
+use warnings;
+use Test::More;
+
+BEGIN {
+ plan skip_all => 'Slow test skipped unless $ENV{TEST_SLOW} is set'
+ unless $ENV{TEST_SLOW};
+}
+
+use Plack::Test::Suite;
+use AnyEvent;
+
+use HTTP::Request;
+use HTTP::Request::Common;
+
+my $LOOPS = 1024; # Default max fds on linux.
+
+sub gentest {
+ my $name = shift;
+ return ($name, sub {
+ my $cb = shift;
+ for (1..$LOOPS) {
+ alarm 2;
+ local $SIG{ALRM} = sub {
+ fail("Timed out");
+ exit;
+ };
+ my $res = $cb->(GET "http://127.0.0.1/");
+ is $res->code, 200, "$name $_ of $LOOPS";
+ alarm 0;
+ }
+ });
+}
+
+local @Plack::Test::Suite::TEST = (
+ [
+ gentest('BadResponse'),
+ sub {
+ return [
+ 200,
+ [ 'Content-Type' => 'text/plain', ],
+ 'Hello'
+ ];
+ },
+ ],
+ [
+ gentest('GoodResponse'),
+ sub {
+ return [
+ 200,
+ [ 'Content-Type' => 'text/plain', ],
+ ['Hello']
+ ];
+ },
+ ],
+);
+
+# prevent Lint middleware from being used
+Plack::Test::Suite->run_server_tests(sub {
+ my($port, $app) = @_;
+ my $server = Plack::Loader->load("Twiggy", port => $port, host => "127.0.0.1");
+ $server->run($app);
+});
+
+done_testing();
+
Please sign in to comment.
Something went wrong with that request. Please try again.