From 39c0186c09228732b17f6dc5da044c5a6d585077 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 5 Jun 2023 10:34:46 -0400 Subject: [PATCH] Bug 33898: background_jobs_worker.pl may leave defunct children processes for extended periods of time It appears that the background jobs worker can leave defunct processes for periods of time. Though it is mostly harmless, it would be nice if that did not happen. Children are reaped automatically when start or wait_all_children are called. We only call start when a new job is found, and wait_all_children after exiting our while loop. The solution is to simply call reap_all_children after we sleep. This is a non-blocking call that will clean up those defunct processes. Test Plan: 1) Disable Rabbit 2) Set background_jobs_worker/max_processes to something like 5 3) Restart all the things! 4) Run a bunch of elastic index updates 5) Verify you have defunct processes 6) Apply this patch 7) Run more elastic index updates 8) Defunct processes should disappear every 10 seconds or so! If you do not see defunct processes, the test plan is to simply verify everything continues to work as expected. --- misc/workers/background_jobs_worker.pl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/misc/workers/background_jobs_worker.pl b/misc/workers/background_jobs_worker.pl index c54610458f..101d33f80e 100755 --- a/misc/workers/background_jobs_worker.pl +++ b/misc/workers/background_jobs_worker.pl @@ -92,6 +92,12 @@ try { my $pm = Parallel::ForkManager->new($max_processes); +$SIG{ALRM} = sub { + $pm->reap_finished_children(); + alarm(1); +}; +alarm(1); + if ( $conn ) { # FIXME cf note in Koha::BackgroundJob about $namespace my $namespace = C4::Context->config('memcached_namespace'); -- 2.30.2