in reply to Re: Double Click of Death on Perl Web Server
in thread Double Click of Death on Perl Web Server

Glad that you've solved it, but your example has another issue:
while (my $client = $server->accept) { ... } eval { close $client } # autodie in use

This eval doesn't do any good. Outside of the while loop the lexical variable $client isn't declared, so you are trying to close an undefined value, then throw away the error. Both use warnings; and use strict; should complain about that. I guess you want to disconnect within the loop?

Replies are listed 'Best First'.
Re^3: Double Click of Death on Perl Web Server
by Anonymous Monk on Sep 30, 2018 at 16:07 UTC
    Apologies for the typo:
    
    my $server = IO::Socket::INET->new(...);
    
    while (my $client = $server->accept) {
      while (<$client>) {
        ...
      }
      ...
      close $client;               # server dies
      eval { close $client }       # does not die
      shutdown $client, 2;         # dies
      eval { shutdown $client, 2 } # does not die
    }
    close $server;
    
      Fork it:
      my $server = IO::Socket::INET->new(...); while (my $client = $server->accept) { if (my $pid = fork()) { # parent waits for another connection close $client } elsif (defined $pid) { # child handles the request while (<$client>) { ... } ... close $client; close $server; exit; } } close $server;

      2018-10-06 Athanasius changed pre tags to code tags