(everything in this reply is untested)

Your main problem is here:

while (my $conn = $socket->accept) {
Accept failing is not usually fatal and should not terminate your loop. In particular, if you get a signal, accept can return without result with $! set to EINTR. And you get signals when your children die.

This doesn't happen in somewhat older perls since they by default have a setting to restart slow systemcalls (but the problem would reappear in really old perls which didn't yet do that).

In new perls (since 5.8) signals only set a flag and handlers only get executed if the perl dispatcher is in a safe state and sees the flag. But that forced the developers to turn off the restarting of slow systemcalls since otherwise actual running of the signal handler code can be indefinitely delayed (the flag would get set, but since the systemcall gets restarted it still doesn't get to the dispatcher, so nothing gets executed)

On UNIX versions that support it, you could avoid getting child signals at all by using

$SIG{CHLD} = "IGNORE";
But that just sets you up to take the fall when you start handling other kinds of signals.

So just change the loop to something like:

use POSIX qw(EINTR); ... while (1) { my $conn = $socket->accept; if (!$conn) { warn("Accept error: $!" if $! != EINTR; next; } .... }

In reply to Re^3: Fork parent process dies unexpectedly by thospel
in thread Fork parent process dies unexpectedly by iang

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.