Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix infinite loop when connection is closed while receiving response …

…content
  • Loading branch information...
commit baeebef008450fa40a43e21a89614bc20e58b55d 1 parent a94a0da
@kazuho authored
Showing with 74 additions and 7 deletions.
  1. +10 −6 README
  2. +3 −1 lib/Starlet/Server.pm
  3. +61 −0 t/03post.t
View
16 README
@@ -9,8 +9,8 @@ SYNOPSIS
% plackup -s Starlet --port=80 [options] your-app.psgi
DESCRIPTION
- Starlet is a standalone HTTP/1.0 server formerly known as
- Plack::Server::Standalone::Prefork and
+ Starlet is a standalone HTTP/1.0 server with keep-alive support,
+ formerly known as Plack::Server::Standalone::Prefork and
Plack::Server::Standalone::Prefork::Server::Starter.
The server supports following features, and is suitable for running HTTP
@@ -44,10 +44,14 @@ COMMAND LINE OPTIONS
(default: 100)
NOTES
- If you are looking for a standalone preforking HTTP server, then you
- should really look at Starman. However if your all want is a simple HTTP
- server that runs behind a reverse proxy, this good old module still does
- what it used to.
+ Starlet is designed and implemented to be simple, secure and fast,
+ especially for running as a HTTP application server running behind a
+ reverse proxy. It only depends on a minimal number of well-designed (and
+ well-focused) modules.
+
+ On the other hand if you are looking for a standalone preforking HTTP
+ server that receives HTTP requests directly from the Internet, then you
+ should look at Starman.
SEE ALSO
Parallel::Prefork Starman Server::Starter
View
4 lib/Starlet/Server.pm
@@ -163,7 +163,9 @@ sub handle_connection {
$chunk = $buf;
$buf = '';
} else {
- $self->read_timeout($conn, \$chunk, $cl, 0, $self->{timeout});
+ $self->read_timeout(
+ $conn, \$chunk, $cl, 0, $self->{timeout})
+ or return;
}
$buffer->print($chunk);
$cl -= length $chunk;
View
61 t/03post.t
@@ -0,0 +1,61 @@
+use strict;
+use warnings;
+
+use LWP::UserAgent;
+use Plack::Runner;
+use Test::More;
+use Test::TCP;
+
+warn $$;
+
+test_tcp(
+ server => sub {
+ my $port = shift;
+ my $runner = Plack::Runner->new;
+ $runner->parse_options(
+ qw(--server Starlet --max-workers 0 --port), $port,
+ );
+ $runner->run(
+ sub {
+ my $env = shift;
+ my $buf = '';
+ while (length($buf) != $env->{CONTENT_LENGTH}) {
+ my $rlen = $env->{'psgi.input'}->read(
+ $buf,
+ $env->{CONTENT_LENGTH} - length($buf),
+ length($buf),
+ );
+ last unless $rlen > 0;
+ }
+ return [
+ 200,
+ [ 'Content-Type' => 'text/plain' ],
+ [ $buf ],
+ ];
+ },
+ );
+ },
+ client => sub {
+ my $port = shift;
+ note 'send a broken request';
+ my $sock = IO::Socket::INET->new(
+ PeerAddr => "127.0.0.1:$port",
+ Proto => 'tcp',
+ ) or die "failed to connect to server:$!";
+ $sock->print(<< "EOT");
+POST / HTTP/1.0\r
+Content-Length: 6\r
+\r
+EOT
+ undef $sock;
+ note 'send next request';
+ my $ua = LWP::UserAgent->new;
+ $ua->timeout(10);
+ my $res = $ua->post("http://127.0.0.1:$port/", { a => 1 });
+ ok $res->is_success;
+ is $res->code, 200;
+ is $res->content, 'a=1';
+ },
+);
+
+done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.