Ticket #279 (closed defect: fixed)
[PATCH] process-quarantine.pl loops forever when the -sub script dies w/ non-0 exit
| Reported by: | jnorell | Owned by: | rjl |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.0.1 |
| Component: | Perl scripts | Version: | 1.0.0 |
| Severity: | normal | Keywords: | |
| Cc: |
Description
I inadvertently updated to DBD-mysql version 3 and had the problem with process-quarantine-sub.pl dieing with the error:
Out of memory! Out of memory! Callback called exit.
and an exit status of 12. Downgrading to a version < 3.0 will fix that, but combined with the design of process-quarantine.pl, it has the effect of almost completely shutting down the mail system. The process-quarantine-sub.pl script returns the number of items processed through the exit() value, and the parent loops until it exit(0)'s. With the above problem, I keep getting an exit value of 12, so the parent loops forever, hogging cpu, memory and database connections.
This is a bit of a hack/ugly, but not being a perl guru, it wasn't
terribly obvious how to get both stdout and the exit value from a child process, so this is what I came up with. I tested it works when the -sub script fails; specifically it does:
# ./process-quarantine.pl Out of memory! Out of memory! Callback called exit. subroutine died with error status: 12 at ./process-quarantine.pl line 182, <CL> line 1. #
And works with a downgraded DBD-mysql, too:
# ./process-quarantine.pl --learn Learned mail item 3247 as SPAM Processing completed: 0 items processed in 1 runs. #
Lightly tested, but working so far.
--- process-quarantine.pl.orig 2006-03-08 15:17:54.000000000 -0700 +++ process-quarantine.pl 2006-03-09 10:41:05.000000000 -0700 @@ -164,13 +164,28 @@
push(@cl_array, "--ham-only") if ($hamonly); # process ham only push(@cl_array, "--debug") if ($debug); # turn on debugging mode push(@cl_array, "--quiet") if ($quiet); # turn on quiet mode
+push(@cl_array, "
# Call the subroutine until there are no items left to process my $total_items_processed = 0; my $total_processing_runs = 0; my $items_processed = -1; while ($items_processed != 0) {
- $items_processed = system(@cl_array) / 256; + $items_processed = 0;
+ open(CL, "$cl_command |")
$total_items_processed += $items_processed; $total_processing_runs++; if ($debug) {
--- process-quarantine-sub.pl.orig 2006-03-08 15:18:00.000000000 -0700 +++ process-quarantine-sub.pl 2006-03-08 16:23:59.000000000 -0700 @@ -111,7 +111,7 @@
{
my ($msg) = @_;
- print $msg . "\n"; + print STDERR $msg . "\n";
exit 0;
}
@@ -558,5 +558,6 @@
# Disconnect from the database $dbh->disconnect;
-# We're done, return the total number of items processed. -exit ($spamcount + $hamcount); +# We're done, print the total number of items processed and return. +print ($spamcount + $hamcount); +exit(0);

