SIG{"PIPE"}

SIG{"PIPE"}

am 04.10.2007 03:41:38 von Petr Vileta

I wrote some script to grab web pages, parse and store data to MySQL
database. On my local PC script work fine but on hosting server many times
fail for ungnown reason. So I write this to script

$SIG{'QUIT'}=sub {errexit("SIG-QUIT");};
$SIG{'TERM'}=sub {errexit("SIG-TERM")};
$SIG{'PIPE'}=sub {errexit("SIG-PIPE")};
$SIG{'__DIE__'}=sub {errexit("SIG-DIE")};

where errxit() is my function to write text to log file and exit. Now I know
that script fail for SIG{'PIPE'} but I don't know why. For get webpage I use
LWP module and I get from 20 to 50 pages before SIG{'PIPE'} terminate my
script.
Can anybody describe me in which cases SIG{'PIPE'} can occur?
--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)

Re: SIG{"PIPE"}

am 04.10.2007 13:57:03 von Ben Morrow

Quoth "Petr Vileta" :
> I wrote some script to grab web pages, parse and store data to MySQL
> database. On my local PC script work fine but on hosting server many times
> fail for ungnown reason. So I write this to script
>
> $SIG{'QUIT'}=sub {errexit("SIG-QUIT");};
> $SIG{'TERM'}=sub {errexit("SIG-TERM")};
> $SIG{'PIPE'}=sub {errexit("SIG-PIPE")};
> $SIG{'__DIE__'}=sub {errexit("SIG-DIE")};
>
> where errxit() is my function to write text to log file and exit. Now I know
> that script fail for SIG{'PIPE'} but I don't know why. For get webpage I use
> LWP module and I get from 20 to 50 pages before SIG{'PIPE'} terminate my
> script.
> Can anybody describe me in which cases SIG{'PIPE'} can occur?

SIGPIPE is sent if you attempt to write to a pipe which has been closed.
'Pipe' here includes SOCK_STREAM sockets, at least on some systems. If
you ignore SIGPIPE ($SIG{PIPE} = 'IGNORE';) then instead of the signal
the write will fail with EPIPE.

A wild guess: is this a CGI script, and the browser is timing out the
request before you've finished, so you get a SIGPIPE trying to write to
STDOUT?

Ben

Re: SIG{"PIPE"}

am 04.10.2007 17:07:53 von Petr Vileta

Ben Morrow wrote:
> Quoth "Petr Vileta" :
>> I wrote some script to grab web pages, parse and store data to MySQL
>> database. On my local PC script work fine but on hosting server many
>> times fail for ungnown reason. So I write this to script
>>
>> $SIG{'QUIT'}=sub {errexit("SIG-QUIT");};
>> $SIG{'TERM'}=sub {errexit("SIG-TERM")};
>> $SIG{'PIPE'}=sub {errexit("SIG-PIPE")};
>> $SIG{'__DIE__'}=sub {errexit("SIG-DIE")};
>>
>> where errxit() is my function to write text to log file and exit.
>> Now I know that script fail for SIG{'PIPE'} but I don't know why.
>> For get webpage I use LWP module and I get from 20 to 50 pages
>> before SIG{'PIPE'} terminate my script.
>> Can anybody describe me in which cases SIG{'PIPE'} can occur?
>
> SIGPIPE is sent if you attempt to write to a pipe which has been
> closed. 'Pipe' here includes SOCK_STREAM sockets, at least on some
> systems. If you ignore SIGPIPE ($SIG{PIPE} = 'IGNORE';) then instead
> of the signal the write will fail with EPIPE.
>
> A wild guess: is this a CGI script, and the browser is timing out the
> request before you've finished, so you get a SIGPIPE trying to write
> to STDOUT?
>
Thanks for your response. This script is not a CGI but a cron job. Is
possible to get a line number where script got SIGPIPE?
--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)

Re: SIG{"PIPE"}

am 04.10.2007 17:30:02 von Paul Lalli

On Oct 4, 11:07 am, "Petr Vileta" wrote:

> Is possible to get a line number where script got SIGPIPE?

perldoc -f caller

Paul Lalli

Re: SIG{"PIPE"}

am 04.10.2007 18:11:21 von Ben Morrow

Quoth "Petr Vileta" :
>
> Thanks for your response. This script is not a CGI but a cron job. Is
> possible to get a line number where script got SIGPIPE?

use Carp qw/confess/;

$SIG{PIPE} = sub { confess 'SIGPIPE'; };

will give you a whole stacktrace.

Ben

Re: SIG{"PIPE"}

am 05.10.2007 01:56:46 von Big and Blue

Petr Vileta wrote:
> I wrote some script to grab web pages, parse and store data to MySQL
> database. On my local PC script work fine but on hosting server many
> times fail for ungnown reason.

One thing to bear in mind is that you can have a script that sometimes gets
SIGPIPE and sometimes doesn't.

As has been noted, it happens if you write to a closed pipe, e.g. a
filehandle open by:

open FH, "| command to run";

But pipes have buffers, so if the amount of data you write to it is small
you may get it into the buffer before the pipe is closed. So if you don't
see it as you start debugging, try writing more data to it.



--
Just because I've written it doesn't mean that
either you or I have to believe it.

Re: SIG{"PIPE"}

am 05.10.2007 06:36:08 von Petr Vileta

Big and Blue wrote:
> Petr Vileta wrote:
>> I wrote some script to grab web pages, parse and store data to MySQL
>> database. On my local PC script work fine but on hosting server many
>> times fail for ungnown reason.
>
> One thing to bear in mind is that you can have a script that
> sometimes gets SIGPIPE and sometimes doesn't.
>
> As has been noted, it happens if you write to a closed pipe, e.g. a
> filehandle open by:
>
> open FH, "| command to run";
>
I checked my script and log written by script and I thing this is not a
reason. I use pipe only for send data to sendmail and this work already.
I'm not sure about LWP. Use LWP some pipes?
--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)

Re: SIG{"PIPE"}

am 06.10.2007 02:31:01 von Big and Blue

Petr Vileta wrote:
>>
> I checked my script and log written by script and I thing this is not a
> reason. I use pipe only for send data to sendmail and this work already.

Well, it can fail - you send a larger message than you expect because of
a bug/problem elsewhere in the program and sendmail fills up the disk or
reaches its size limit.


--
Just because I've written it doesn't mean that
either you or I have to believe it.