http://www.perlmonks.org?node_id=1001264
GwenDragon has asked for the wisdom of the Perl Monks concerning the following question:

Please, I'd like to know, why SIPIPE is not trapped after aborting a CGI connection and using sleep()?

Testcase:

1. Uploaded CGI to webserver

2. fetched it with browser

3. After 5-10 seconds hit abort button in browser

4. Inspect debug.txt

5. Only END output is in debug file.

#!/usr/bin/perl $SIG{PIPE} = sub { open my $fh, '>>', 'debug.txt'; print $fh "Debug: died PIPE.\n"; close $fh; CORE::die "Pipe: @_\n"; }; $| = 1; use strict; use warnings; use CGI (); my $q = CGI->new(); print $q->header(); print "output #1\n"; warn "Debug: RUNNING"; sleep 30; print "output #2\n"; END { open my $fh, '>>', 'debug.txt'; print $fh "Debug: END block.\n"; close $fh; }

Then i thought, using pragma traphandler would help so solve the prob. I tried use sigtrap 'handler' => \&my_handler, 'normal-signals'; to trap SIGPIPE, without any effort.

After removing sleep in my testcase the trapping of SIGPIPE by my signal handler works fine.

Why does sleep disable signal trapping and the installed signal handler? Can yo explain this ti me?

Replies are listed 'Best First'.
Re: SIGPIPE not trapped after sleep in CGI
by zwon (Abbot) on Oct 28, 2012 at 13:37 UTC