You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jim Albert <ji...@netrition.com> on 2004/06/09 23:32:54 UTC

mod_perl2 timely catching SIGPIPE

I'm trying to determine how to have my mod_perl apache server properly 
catch a SIGPIPE signal in a timely manner.

My environment is Apache/2.0.49 (Fedora) and mod_perl 2.

In my conf.d/perl.conf file I have the following:
PerlFixupHandler Apache::SIG2

I have created Apache::SIG2.pm as follows:
----------
package Apache::SIG2;

use strict;
use Apache::RequestRec;
use Apache::Const;

sub handler {
     my $r = shift;
     if (!$r->main) {
         print STDERR ("In handler\n");
         $SIG{PIPE} = \&PIPE;
     }
     return OK;
}

sub PIPE {
      my($signal) = @_;
      print STDERR ("signal caught = $signal\n");
}

1;
----------

For ease of tracing, I have set up my apache environment so as to have 
only one mod_perled httpd child running.

When an httpd request is made, I see "In handler" so I know that a 
SIGPIPE signal should be caught.

However, when I cause a condition that generates a SIGPIPE, such as 
pressing the browser stop button, my SIGPIPE handler, PIPE, is not 
immediately called.  Strangely, PIPE is called the next time a new httpd 
request is handled by this same httpd child.  I ran my httpd server with 
strace and I do see the following at the time the connection is broken:
--- SIGPIPE (Broken pipe) @ 0 (0) ---
so the SIGPIPE is being generated at the appropriate time, but the 
mod_perled httpd child is not detecting it (or at least not executing my 
signal handler routine) until the next httpd request.

The http request I make to test this is a non_modperl CGI generating 
lots of output with autoflush turned on ($|=1) so that there is plenty 
of output being sent over the pipe that will be broken by me clicking 
the browser stop button.

Under Apache/1.3.27 and mod_perl/1.27 I had a very similar 
PerlFixupHandler in place (a slightly modified Apache::SIG.pm) to catch 
a SIGPIPE and the SIGPIPE was caught and my signal handler executed at 
the correct time... when the connection was broken by the browser.  I 
would like to be able to continue to catch a SIGPIPE like this under 
Apache2/modperl2.  Can anyone offer any suggestions as to how to get my 
signal handler, PIPE, executed as soon as the SIGPIPE is generated?

Thanks
Jim Albert



-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: mod_perl2 timely catching SIGPIPE

Posted by Stas Bekman <st...@stason.org>.
[Jim, please keep the thread on the list, so others will be able to re-use 
that discussion via archives later on when they hit the same problem. Thanks.]

>> Excellent, looking forward for your docs Jim.
> 
> 
> Is there any particular format people use to report such findings?  Any 
> examples online?  I don't really consider this issue to be a bug, rather 
> a need to understand how perl 5.8 handles signals.  But, I would guess 
> there is some mod_perl doc that would be appropriate to include my 
> signal explanation.

Right, this is not a bug.

Here is how to submit mod_perl doc patches in general:

http://perl.apache.org/download/docs.html
http://perl.apache.org/contribute/index.html

But if that's too hard, just submit your original report and the solution 
(including other solutions I've mentioned) as a short article in pod (or plain 
text) and I'll handle the rest.

Most likely it should belong here:
http://perl.apache.org/docs/2.0/user/coding/coding.html
but since this is a generic perl issue, not quite specific to mp2, it's 
probably better suited to:
http://perl.apache.org/docs/general/perl_reference/perl_reference.html
with cross-references from:
http://perl.apache.org/docs/2.0/user/coding/coding.html
http://perl.apache.org/docs/1.0/guide/porting.html

> Once again... thanks so much for your help.  What a relief after 
> battling this problem for 3 days.

You're welcome, Jim :)

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: mod_perl2 timely catching SIGPIPE

Posted by Stas Bekman <st...@stason.org>.
Jim Albert wrote:
> Stas Bekman wrote:
> 
>> Jim Albert wrote:
>>
>>> I'm trying to determine how to have my mod_perl apache server 
>>> properly catch a SIGPIPE signal in a timely manner.
>>>
>>> My environment is Apache/2.0.49 (Fedora) and mod_perl 2.
>>
>>
>>
>> Jim, please *always* report bugs and problems following these guidelines!
>> http://perl.apache.org/bugs/
>> and save yourself and us time. Thank you!
>>
>>> In my conf.d/perl.conf file I have the following:
>>> PerlFixupHandler Apache::SIG2
>>
>>
>> [...]
>>
>>> Under Apache/1.3.27 and mod_perl/1.27 I had a very similar 
>>> PerlFixupHandler in place (a slightly modified Apache::SIG.pm) to 
>>> catch a SIGPIPE and the SIGPIPE was caught and my signal handler 
>>> executed at the correct time... when the connection was broken by the 
>>> browser.  I would like to be able to continue to catch a SIGPIPE like 
>>> this under Apache2/modperl2.  Can anyone offer any suggestions as to 
>>> how to get my signal handler, PIPE, executed as soon as the SIGPIPE 
>>> is generated?
>>
>>
>>
>> What perl version are you using now (and which one have you used with 
>> 1.3.x?) (which you were supposed to sent as a part of the bug report).
> 
> 
> In my mod_perl environment (Apache 1.3 / mod_perl 1.27) where my perl 
> handler catches and immediately handles the SIGPIPE I am using perl 5.6.1.
> 
> In my mod_perl environment (Apache2.0.49 / mod_perl 2) where my perl 
> handler properly catches the SIGPIPE, but does not handle it immediately 
> I am using perl 5.8.3.

So most likely you'd have had the same problem with mod_perl 1.27, if you were 
to use perl 5.8.x there.

>> I don't think this has anything to do with what mod_perl version you 
>> are using.
> 
>  >
>  > Starting from 5.8.0 perl delays signal delivery, making signals safe.
> [...]
> 
> Stas, you are absolutely correct... thanks a lot!  I added the following 
> line to my server_startup.pl (Apache2.0.49 / mod_perl 2) which gets 
> included from my conf.d/perl.conf file:
> $ENV{PERL_SIGNALS} = "unsafe";
> 
> With that line in place, my PerlFixupHandler now catches a SIGPIPE and 
> immediately executes the SIGPIPE signal handler.
> 
> I hadn't had any significant problem that I noticed using "unsafe" 
> signals in the past and  I need the functionality that "unsafe" signals 
> provide me, so I'm going to go with "unsafe" signals in my 
> apache2/mod_perl2/perl5.8 environment.

Good to hear that it worked :)

>> Please let us know which technique has worked for you and it'd be 
>> great to have a section documenting this area, including full examples 
>> as in your original bug report.
> 
> 
> I've been researching this problem for several days so I'm anxious to 
> get an Apache2/mod_perl2 system into production now that I have a 
> solution.  When I get some time I'll post a detailed explanation of this 
> problem with examples to this mailing list.

Excellent, looking forward for your docs Jim.


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: mod_perl2 timely catching SIGPIPE

Posted by Jim Albert <ji...@netrition.com>.
Stas Bekman wrote:

> Jim Albert wrote:
> 
>> I'm trying to determine how to have my mod_perl apache server properly 
>> catch a SIGPIPE signal in a timely manner.
>>
>> My environment is Apache/2.0.49 (Fedora) and mod_perl 2.
> 
> 
> Jim, please *always* report bugs and problems following these guidelines!
> http://perl.apache.org/bugs/
> and save yourself and us time. Thank you!
> 
>> In my conf.d/perl.conf file I have the following:
>> PerlFixupHandler Apache::SIG2
> 
> [...]
> 
>> Under Apache/1.3.27 and mod_perl/1.27 I had a very similar 
>> PerlFixupHandler in place (a slightly modified Apache::SIG.pm) to 
>> catch a SIGPIPE and the SIGPIPE was caught and my signal handler 
>> executed at the correct time... when the connection was broken by the 
>> browser.  I would like to be able to continue to catch a SIGPIPE like 
>> this under Apache2/modperl2.  Can anyone offer any suggestions as to 
>> how to get my signal handler, PIPE, executed as soon as the SIGPIPE is 
>> generated?
> 
> 
> What perl version are you using now (and which one have you used with 
> 1.3.x?) (which you were supposed to sent as a part of the bug report).

In my mod_perl environment (Apache 1.3 / mod_perl 1.27) where my perl 
handler catches and immediately handles the SIGPIPE I am using perl 5.6.1.

In my mod_perl environment (Apache2.0.49 / mod_perl 2) where my perl 
handler properly catches the SIGPIPE, but does not handle it immediately 
I am using perl 5.8.3.


> I 
> don't think this has anything to do with what mod_perl version you are 
> using.
 >
 > Starting from 5.8.0 perl delays signal delivery, making signals safe.
[...]

Stas, you are absolutely correct... thanks a lot!  I added the following 
line to my server_startup.pl (Apache2.0.49 / mod_perl 2) which gets 
included from my conf.d/perl.conf file:
$ENV{PERL_SIGNALS} = "unsafe";

With that line in place, my PerlFixupHandler now catches a SIGPIPE and 
immediately executes the SIGPIPE signal handler.

I hadn't had any significant problem that I noticed using "unsafe" 
signals in the past and  I need the functionality that "unsafe" signals 
provide me, so I'm going to go with "unsafe" signals in my 
apache2/mod_perl2/perl5.8 environment.

> Please let us know which technique has worked for you and it'd be great 
> to have a section documenting this area, including full examples as in 
> your original bug report.

I've been researching this problem for several days so I'm anxious to 
get an Apache2/mod_perl2 system into production now that I have a 
solution.  When I get some time I'll post a detailed explanation of this 
problem with examples to this mailing list.

Jim Albert



-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: mod_perl2 timely catching SIGPIPE

Posted by Stas Bekman <st...@stason.org>.
Jim Albert wrote:
> I'm trying to determine how to have my mod_perl apache server properly 
> catch a SIGPIPE signal in a timely manner.
> 
> My environment is Apache/2.0.49 (Fedora) and mod_perl 2.

Jim, please *always* report bugs and problems following these guidelines!
http://perl.apache.org/bugs/
and save yourself and us time. Thank you!

> In my conf.d/perl.conf file I have the following:
> PerlFixupHandler Apache::SIG2
[...]
> Under Apache/1.3.27 and mod_perl/1.27 I had a very similar 
> PerlFixupHandler in place (a slightly modified Apache::SIG.pm) to catch 
> a SIGPIPE and the SIGPIPE was caught and my signal handler executed at 
> the correct time... when the connection was broken by the browser.  I 
> would like to be able to continue to catch a SIGPIPE like this under 
> Apache2/modperl2.  Can anyone offer any suggestions as to how to get my 
> signal handler, PIPE, executed as soon as the SIGPIPE is generated?

What perl version are you using now (and which one have you used with 1.3.x?) 
(which you were supposed to sent as a part of the bug report). I don't think 
this has anything to do with what mod_perl version you are using.

Starting from 5.8.0 perl delays signal delivery, making signals safe. For more 
information please see:
http://www.perldoc.com/perl5.8.4/pod/perl58delta.html#Safe-Signals
http://www.perldoc.com/perl5.8.4/pod/perlipc.html#Deferred-Signals-(Safe-Signals)

If you want to disable that perl feature, you can either recompile perl 
(starting from 5.8.1):
http://www.perldoc.com/perl5.8.4/pod/perl581delta.html#Unsafe-signals-again-available
http://www.perldoc.com/perl5.8.4/pod/perlrun.html#PERL_SIGNALS

Or use POSIX signal handling which bypasses perl signal mechanism:
http://www.perldoc.com/perl5.8.4/pod/POSIX.html#POSIX--SigAction

Please let us know which technique has worked for you and it'd be great to 
have a section documenting this area, including full examples as in your 
original bug report.

Thanks.

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html