[Opensrf-commits] r2114 - branches/rel_2_0/src/perl/lib/OpenSRF (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Nov 29 14:19:06 EST 2010
Author: erickson
Date: 2010-11-29 14:19:02 -0500 (Mon, 29 Nov 2010)
New Revision: 2114
Modified:
branches/rel_2_0/src/perl/lib/OpenSRF/Server.pm
Log:
add fault tolerance (e.g. recover from interrupted select/sysread); always perform idle maintenance when there are any active child processes; exit check status early when no active processes exist
Modified: branches/rel_2_0/src/perl/lib/OpenSRF/Server.pm
===================================================================
--- branches/rel_2_0/src/perl/lib/OpenSRF/Server.pm 2010-11-29 19:18:41 UTC (rev 2113)
+++ branches/rel_2_0/src/perl/lib/OpenSRF/Server.pm 2010-11-29 19:19:02 UTC (rev 2114)
@@ -144,7 +144,9 @@
# when we hit equilibrium, there's no need for regular
# maintenance, so set wait_time to 'forever'
- $wait_time = -1 unless $self->perform_idle_maintenance;
+ $wait_time = -1 if
+ !$self->perform_idle_maintenance and # no maintenance performed this time
+ @{$self->{active_list}} == 0; # no active children
}
}
}
@@ -232,18 +234,31 @@
sub check_status {
my($self, $block) = @_;
+ return unless @{$self->{active_list}};
+
my $read_set = IO::Select->new;
$read_set->add($_->{pipe_to_child}) for @{$self->{active_list}};
- my @handles = $read_set->can_read(($block) ? undef : 0) or return;
+ my @pids;
- my $pid = '';
- my @pids;
- for my $pipe (@handles) {
- sysread($pipe, $pid, STATUS_PIPE_DATA_SIZE) or next;
- push(@pids, int($pid));
+ while (1) {
+
+ # if can_read or sysread is interrupted while bloking, go back and
+ # wait again until we have at least 1 free child
+
+ if(my @handles = $read_set->can_read(($block) ? undef : 0)) {
+ my $pid = '';
+ for my $pipe (@handles) {
+ sysread($pipe, $pid, STATUS_PIPE_DATA_SIZE) or next;
+ push(@pids, int($pid));
+ }
+ }
+
+ last unless $block and !@pids;
}
+ return unless @pids;
+
$chatty and $logger->internal("server: ".scalar(@pids)." children reporting for duty: (@pids)");
my $child;
@@ -276,7 +291,7 @@
while(1) {
my $pid = waitpid(-1, ($shutdown) ? 0 : WNOHANG);
- return if $pid <= 0;
+ last if $pid <= 0;
$chatty and $logger->internal("server: reaping child $pid");
More information about the opensrf-commits
mailing list