Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

SIGPIPE not trapped after sleep in CGI

by GwenDragon (Novice)
on Oct 28, 2012 at 11:35 UTC ( [id://1001264]=perlquestion: print w/replies, xml ) Need Help??

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

    Try to add following two lines after print "output #2\n";:

    sleep 5; print "output #3\n";
    and you will get your SIGPIPE.

    Update:

    So after you printed "output #1" you hit abort in browser, browser sent "FIN" to server, that means that it will not send any data to server, server considers connection open write only after that. Then you print "output #2", server sends it to browser as it thinks connection is still open for writing, no error here and no SIGPIPE. Client receives this "output #2" and replies with "RST" as it considers connection completely closed. After server got "RST" it realise that connection is closed, now if you try to write anything into socket, you will get SIGPIPE.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1001264]
Approved by McDarren
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-19 15:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found