print doesn't always write to the underlying file handle immediately. What you print often ends up in a buffer that gets written to the underlying file handle on a later print, or when the handle is closed. This is an optimization called "buffering".

What's happening here is that the actual printing is being delayed until you call close, but the browser has already closed the socket by that time (to abort the first request before making the second request). Your code is therefore attempting to write to a closed socket, which normally results in a SIGPIPE signal killing your process, but you must be on Windows or have that signal ignored, because it results in close failing instead. autodie converts this into an exception.

All of that is perfectly fine! The problem is in your handling of that error, or lack thereof. Your server code should handle all exceptions that occur while handling a request. As such, your code should look like this:

use autodie; my $server = IO::Socket::INET->new(...); while (1) { my $client = $server->accept() or die("Can't accept connections: $!\n"); if (!eval { ... close($client); return 1; # No exception }) { warn("Error servicing request: $@"); } }

In reply to Re^4: Double Click of Death on Perl Web Server by ikegami
in thread Double Click of Death on Perl Web Server by Anonymous Monk

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.