Mailing List Archive

svn commit: r179513 - in /spamassassin/trunk: lib/Mail/SpamAssassin/SpamdForkScaling.pm spamd/spamd.raw
Author: jm
Date: Wed Jun 1 22:18:39 2005
New Revision: 179513

URL: http://svn.apache.org/viewcvs?rev=179513&view=rev
Log:
improve error reporting and recovery in prefork code; fix bug in signal-handling warn message whereby half of it was being lost; also, reorder a little bit of spamd startup to make test suite faster and possibly fix Michael's build slaves

Modified:
spamassassin/trunk/lib/Mail/SpamAssassin/SpamdForkScaling.pm
spamassassin/trunk/spamd/spamd.raw

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/SpamdForkScaling.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin/SpamdForkScaling.pm?rev=179513&r1=179512&r2=179513&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/SpamdForkScaling.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/SpamdForkScaling.pm Wed Jun 1 22:18:39 2005
@@ -85,6 +85,23 @@
delete $self->{kids}->{$pid};
}

+sub child_error_kill {
+ my ($self, $pid, $sock) = @_;
+
+ warn "prefork: killing failed child $pid ".
+ ($sock ? "fd=".$sock->fileno : "");
+
+ # close the socket and remove the child from our list
+ $self->set_child_state ($pid, PFSTATE_KILLED);
+
+ kill 'INT' => $pid;
+ if ($sock) {
+ $sock->close;
+ }
+
+ warn "prefork: killed child $pid";
+}
+
sub set_child_state {
my ($self, $pid, $state) = @_;

@@ -94,7 +111,7 @@
$self->compute_lowest_child_pid();

} else {
- dbg("prefork: child $pid: ignored new state $state, already exited");
+ dbg("prefork: child $pid: ignored new state $state, starting or already exited");
}
}

@@ -109,6 +126,9 @@
if ($l > $p) { $l = $p };
}
$self->{lowest_idle_pid} = $l;
+
+ dbg("prefork: new lowest idle kid: ".
+ ($self->{lowest_idle_pid} ? $self->{lowest_idle_pid} : 'none'));
}

###########################################################################
@@ -266,8 +286,7 @@
# this should not happen, but if it does, trap it here
# before we attempt to call a method on an undef object
warn "prefork: oops! no socket for child $kid, killing";
- delete $self->{kids}->{$kid};
- kill 'INT' => $kid;
+ $self->child_error_kill($kid, $sock);

# retry with another child
return $self->order_idle_child_to_accept();
@@ -276,13 +295,8 @@
if (!$self->syswrite_with_retry($sock, "A....\n"))
{
# failure to write to the child; bad news. call it dead
- warn "prefork: killing rogue child $kid, failed to write: $!\n";
- $self->set_child_state ($kid, PFSTATE_KILLED);
- kill 'INT' => $kid;
-
- # close the socket and remove the child from our list
- delete $self->{kids}->{$kid};
- $sock->close();
+ warn "prefork: killing rogue child $kid, failed to write on fd ".$sock->fileno.": $!\n";
+ $self->child_error_kill($kid, $sock);

# retry with another child
return $self->order_idle_child_to_accept();
@@ -322,7 +336,8 @@
if ($self->{waiting_for_idle_child}) {
my $sock = $self->{backchannel}->get_socket_for_child($kid);
$self->syswrite_with_retry($sock, "A....\n")
- or die "prefork: $kid claimed it was ready, but write failed: $!";
+ or die "prefork: $kid claimed it was ready, but write failed on fd ".
+ $sock->fileno.": ".$!;
$self->{waiting_for_idle_child} = 0;
}
}

Modified: spamassassin/trunk/spamd/spamd.raw
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/spamd/spamd.raw?rev=179513&r1=179512&r2=179513&view=diff
==============================================================================
--- spamassassin/trunk/spamd/spamd.raw (original)
+++ spamassassin/trunk/spamd/spamd.raw Wed Jun 1 22:18:39 2005
@@ -732,11 +732,6 @@

my $remote_port;

-# Fork off our children.
-for ( 1 .. $childlimit ) {
- spawn();
-}
-
# Make the pidfile ...
if (defined $opt{'pidfile'}) {
if (open PIDF, ">$opt{'pidfile'}") {
@@ -752,6 +747,11 @@
# The test suite does this!
info("spamd: server pid: $$\n");

+# Fork off our children.
+for ( 1 .. $childlimit ) {
+ spawn();
+}
+
if ($scaling) {
$scaling->set_server_fh($server);
}
@@ -1988,8 +1988,8 @@
}

unless ($$Mail::SpamAssassin::Logger::LOG_SA{INHIBIT_LOGGING_IN_SIGCHLD_HANDLER}) {
- info("spamd: handled cleanup of child pid $pid " .
- (defined $sig) ? "due to SIG$sig" : "");
+ info("spamd: handled cleanup of child pid $pid ".
+ ((defined $sig) ? "due to SIG$sig" : ""));
}
}