LP#1697029 Log and exit on write to dead child
authorBill Erickson <berickxx@gmail.com>
Fri, 9 Jun 2017 17:01:46 +0000 (13:01 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Fri, 8 Sep 2017 19:45:33 +0000 (15:45 -0400)
Confirm that a child process is alive just before attempting to write to
its pipe.  If the child process is dead, log the error, then drop the
message and move on.  This allows the parent to continue servicing
future requests.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>

src/perl/lib/OpenSRF/Server.pm

index dcf44fe..ba463e4 100644 (file)
@@ -303,6 +303,19 @@ sub write_child {
         $self->{sig_pipe} = 0;
         local $SIG{'PIPE'} = sub { $self->{sig_pipe} = 1; };
 
+        # In rare cases a child can die between creation and first
+        # write, typically a result of a jabber connect error.  Before
+        # sending data to each child, confirm it's still alive.  If it's
+        # not, log the error and drop the message to prevent the parent
+        # process from dying.
+        # When a child dies, all of its attributes are deleted,
+        # so the lack of a pid means the child is dead.
+        if (!$child->{pid}) {
+            $logger->error("server: child is dead in write_child(). ".
+                "unable to send message: $xml");
+            return; # avoid syswrite crash
+        }
+
         # send message to child data pipe
         syswrite($child->{pipe_to_child}, $write_size . $xml);