Similar to the SIGPIPE retry logic wrapped around the parent process'
syswrite call (for sending data to a child process), protect the child's
sysread call (as it reads data from the parent). In pre-2.0, the
sysread step was handled by Net::Server, but now we need to protect it
ourselves.
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
while(1) {
# Start out blocking, when data is available, read it all
+ my $sig_pipe = 0;
+ local $SIG{'PIPE'} = sub { $sig_pipe = 1 };
+
my $buf = '';
my $n = sysread($self->{pipe_to_parent}, $buf, $read_size);
unless(defined $n) {
+
+ if ($sig_pipe) {
+ $logger->info("server: $self got SIGPIPE reading data from parent, retrying...");
+ usleep(50000); # 50 msec
+ next;
+ }
+
$logger->error("server: error reading data pipe: $!") unless EAGAIN == $!;
last;
}