-# Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+#
+# Ensure buffering behavior in -httpd doesn't cause runaway memory use
+# or data corruption
use strict;
use warnings;
use Test::More;
use File::Temp qw/tempdir/;
-use IO::Socket::INET;
use POSIX qw(setsid);
my $git_dir = $ENV{GIANT_GIT_DIR};
my $err = "$tmpdir/stderr.log";
my $out = "$tmpdir/stdout.log";
my $httpd = 'blib/script/public-inbox-httpd';
-my %opts = (
- LocalAddr => '127.0.0.1',
- ReuseAddr => 1,
- Proto => 'tcp',
- Type => SOCK_STREAM,
- Listen => 1024,
-);
-my $sock = IO::Socket::INET->new(%opts);
+my $sock = tcp_server();
my $host = $sock->sockhost;
my $port = $sock->sockport;
my $pid;
{
ok($sock, 'sock created');
- my $cmd = [ $httpd, "--stdout=$out", "--stderr=$err", $psgi ];
+ my $cmd = [ $httpd, '-W0', "--stdout=$out", "--stderr=$err", $psgi ];
ok(defined($pid = spawn_listener(undef, $cmd, [$sock])),
'forked httpd process successfully');
}
my ($code, $mess, %h) = $http->read_response_headers;
is(200, $code, 'got 200 success for pack');
is($max, $h{'Content-Length'}, 'got expected Content-Length for pack');
+
+ # no $http->read_entity_body, here, since we want to force buffering
foreach my $i (1..3) {
sleep 1;
my $diff = $get_maxrss->() - $mem_a;