Broken pipe problem? If so, why?

M

malgosia askanas

I have a mail-handling program written in Perl. It gets passed a mail message,
reads the header, does some processing, and exits. The code for reading
the header is:

$/ = ''; # paragraph mode
$header = <>;

I am invoking this program in a pipe from procmail. For some messages (I
believe, for very large ones) I get the message "Error while writing to
<progname>" in the procmail log. I would be inclined to believe that it's
a broken pipe problem, but if so, why does its occurrence depend on the
message size? The program reads only the header for _all_ messages,
independent of size - yet in a vast majority of cases, procmail does not
complain. Can you advise?


Many thanks in advance,
-malgosia
 
B

Big and Blue

malgosia said:
$/ = ''; # paragraph mode
$header = <>;

I am invoking this program in a pipe from procmail. For some messages (I
believe, for very large ones) I get the message "Error while writing to
<progname>" in the procmail log. I would be inclined to believe that it's
a broken pipe problem, but if so, why does its occurrence depend on the
message size? The program reads only the header for _all_ messages,
independent of size - yet in a vast majority of cases, procmail does not
complain. Can you advise?

The fact that you "only" read the header is the problem (but reading
all of it is not necessarily the solution).

procmail is piping the message to you (can't you configure procmail
just to send teh header?). If the entire message is small enough to fit
into the buffer of a pipe (usually 8kB?) then it will write it all and
things are OK. If it is larger than this though a problem occurs - you
only read the start of the then close the pipe (by exiting). Since you
have closed the pipe while procmail still has it open *it* gets sent a SIGPIPE.

So, you have to look at the procmail config options and:

1) get it to only send headers - if possible only get it to send
information you are interested in.
2) tell it to ignore SIGPIPE if possible

if 2) is not possible then you should read *everything* (but just ignore
the parts aftre the bit you really want).
 
X

xhoster

I have a mail-handling program written in Perl. It gets passed a mail
message, reads the header, does some processing, and exits. The code for
reading the header is:

$/ = ''; # paragraph mode
$header = <>;

I am invoking this program in a pipe from procmail. For some messages (I
believe, for very large ones) I get the message "Error while writing to
<progname>" in the procmail log. I would be inclined to believe that
it's a broken pipe problem, but if so, why does its occurrence depend on
the message size? The program reads only the header for _all_ messages,
independent of size - yet in a vast majority of cases, procmail does not
complain. Can you advise?

Since your Perl program is only reading the header, it must be terminating
while there is still stuff to be read. For short messages, all that stuff
to be read fits in the buffer, so the other end of the pipe doesn't notice.
But for large messages, when the Perl end of the pipe exits the other end
of the pipe gets upset because it is now trying to write to something that
no longer exists. Or something like that.

Xho
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top