From ea72acaf798f3fc6cc0aae8d93771c6dc2a21a57 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 9 Jun 2017 13:01:46 -0400 Subject: [PATCH] LP#1697029 Log and exit on write to dead child 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 Signed-off-by: Galen Charlton --- src/perl/lib/OpenSRF/Server.pm | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/perl/lib/OpenSRF/Server.pm b/src/perl/lib/OpenSRF/Server.pm index dcf44fe..ba463e4 100644 --- a/src/perl/lib/OpenSRF/Server.pm +++ b/src/perl/lib/OpenSRF/Server.pm @@ -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); -- 2.43.2