CGI from Apache, broken pipe

2019-08-28 12:25发布

问题:

What does happen with Apache (or Nginx) running a CGI script when the client (I mean a browser or a TCP gateway) disconnects in the middle?

  1. Does Apache/Nginx log an error? (If yes, which one and where?)

  2. Is the CGI script sent SIGPIPE to?

回答1:

There is no SIGPIPE when Apache CGI script is interrupted.

Tested with the following code:

#!/usr/bin/perl

use strict;
use warnings;

$| = 1;

#$SIG{PIPE} = "IGNORE";
$SIG{PIPE} = sub {
  open my $f, '>', 'log.txt';
  print $f "PIPE: $ENV{SERVER_NAME}\n";
  close $f;
};

print "Content-Type: text/plain\n\n";

sleep 10;

print "OK";