Broken pipe problem? If so, why?

Discussion in 'Perl Misc' started by malgosia askanas, Mar 28, 2005.

  1. 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
    malgosia askanas, Mar 28, 2005
    #1
    1. Advertising

  2. malgosia askanas

    Big and Blue Guest

    malgosia askanas wrote:
    >
    > $/ = ''; # 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).




    --
    Just because I've written it doesn't mean that
    either you or I have to believe it.
    Big and Blue, Mar 28, 2005
    #2
    1. Advertising

  3. malgosia askanas

    Guest

    (malgosia askanas) wrote:
    > 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

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Mar 28, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,803
    Smokey Grindel
    Dec 2, 2006
  2. Steven D'Aprano

    Why are "broken iterators" broken?

    Steven D'Aprano, Sep 21, 2008, in forum: Python
    Replies:
    8
    Views:
    645
  3. Cameron Simpson

    Re: Why are "broken iterators" broken?

    Cameron Simpson, Sep 22, 2008, in forum: Python
    Replies:
    0
    Views:
    580
    Cameron Simpson
    Sep 22, 2008
  4. Fredrik Lundh

    Re: Why are "broken iterators" broken?

    Fredrik Lundh, Sep 22, 2008, in forum: Python
    Replies:
    0
    Views:
    598
    Fredrik Lundh
    Sep 22, 2008
  5. Replies:
    1
    Views:
    221
    Ben Morrow
    Jun 2, 2004
Loading...

Share This Page