in reply to Re^3: Double Click of Death on Perl Web Server
in thread Double Click of Death on Perl Web Server
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: $@"); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Double Click of Death on Perl Web Server
by Anonymous Monk on Oct 02, 2018 at 21:04 UTC | |
by ikegami (Patriarch) on Oct 03, 2018 at 19:52 UTC |