]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
t/httpd-corner: improve EPIPE/SIGPIPE handling
authorEric Wong <e@80x24.org>
Tue, 29 Apr 2025 17:16:45 +0000 (17:16 +0000)
committerEric Wong <e@80x24.org>
Thu, 1 May 2025 21:29:41 +0000 (21:29 +0000)
We'll ignore SIGPIPE as we do in other places so we can get
EPIPE on failed `print' calls.  Furthermore, it's possible we'll
hit EPIPE before we see an 400 HTTP response code when making
bad requests.  I've noticed this problem on slower single CPU
machines.

t/httpd-corner.t

index 2ff40c54f22b9ec89f35c2c59eaeb4baae1f2833..cf67ad28b9b78eef845714bfc6250c14d9aca5c5 100644 (file)
@@ -27,6 +27,7 @@ my $sock = tcp_server();
 my @zmods = qw(PublicInbox::GzipFilter IO::Uncompress::Gunzip);
 my $base_url = 'http://'.tcp_host_port($sock);
 use Config;
+local $SIG{PIPE} = 'IGNORE';
 
 # Make sure we don't clobber socket options set by systemd or similar
 # using socket activation:
@@ -196,10 +197,14 @@ if ('test rejected trailers') {
        "Content-Length: 11\r\nTrailer: a\r\n".$chunk_body."a: b\r\n"]
        ) {
                my ($d, $req) = @$t;
-               my $c = $mkreq->($sock, $d, $req."\r\n");
-               poll_in $c, 30_000 or Carp::croak "timeout";
-               my $buf = do { local $/ = "\r\n\r\n"; <$c> };
-               like $buf, qr!^HTTP/1\.. 400\b!, "$d rejected";
+               my $c = eval { $mkreq->($sock, $d, $req."\r\n") };
+               if ($@) {
+                       ok $!{EPIPE}, "got EPIPE on $d";
+               } else {
+                       poll_in $c, 30_000 or Carp::croak "timeout";
+                       my $buf = do { local $/ = "\r\n\r\n"; <$c> };
+                       like $buf, qr!^HTTP/1\.. 400\b!, "$d rejected";
+               }
        }
 }
 
@@ -310,7 +315,6 @@ my $check_400 = sub {
 };
 
 {
-       local $SIG{PIPE} = 'IGNORE';
        my $conn = $mkreq->($sock, 'excessive header',
                "GET /callback HTTP/1.0\r\n");
        setsockopt $conn, IPPROTO_TCP, TCP_NODELAY, 1;
@@ -586,7 +590,6 @@ SKIP: {
 
 # various DoS attacks against the chunk parser:
 {
-       local $SIG{PIPE} = 'IGNORE';
        my $conn = $mkreq->($sock, '1.1 chunk header excessive',
                "PUT /sha1 HTTP/1.1\r\nTransfer-Encoding:chunked\r\n\r\n");
        setsockopt $conn, IPPROTO_TCP, TCP_NODELAY, 1;