SIP Multi : avoid die in parent
authorBill Erickson <berick@esilibrary.com>
Fri, 13 Sep 2013 14:51:48 +0000 (10:51 -0400)
committerBill Erickson <berick@esilibrary.com>
Fri, 13 Sep 2013 14:53:13 +0000 (10:53 -0400)
Don't allow a connection-level die() to affect the parent process.  The
parent process must be highly resilient.

More logging.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
SIPServer.pm

index 78c6e05..5e577c1 100644 (file)
@@ -213,7 +213,8 @@ sub mux_input {
         if (! defined($self->{service})) {
             syslog( "LOG_ERR", "process_request: Unrecognized server connection: %s:%s/%s",
                 $sockaddr, $port, $proto );
-            die "process_request: Bad server connection";
+            syslog('LOG_ERR', "process_request: Bad server connection");
+            return;
         }
     
         my $transport = $transports{ $self->{service}->{transport} };
@@ -223,7 +224,11 @@ sub mux_input {
             return;
         }
 
-        &$transport($self, $str_fh);
+        eval { &$transport($self, $str_fh) };
+        if ($@) {
+            syslog('LOG_ERR', "ILS login error: $@");
+            return;
+        }
 
         $active_connections{$conn_id} =
             { id         => $conn_id,
@@ -247,7 +252,10 @@ sub mux_input {
     $self = $active_connections{$conn_id}->{net_server};
 
     my $pid = fork();
-    die "Cannot fork: $!" unless (defined($pid) && $pid > -1);
+    if (!defined($pid) or $pid < 0) {
+        syslog('LOG_ERR', "Unable to fork new child process $!");
+        return;
+    }
 
     if ($pid == 0) { # in kid
 
@@ -278,7 +286,8 @@ sub mux_input {
 sub mux_close {
     my ($self, $mux, $fh) = @_;
     delete $active_connections{''.$fh};
-    syslog("LOG_DEBUG", "multi: cleaning up child: $fh");
+    syslog("LOG_DEBUG", "multi: cleaning up child: $fh; ". 
+        scalar(keys %active_connections)." remain");
 }