Bugzilla – Attachment 154339 Details for
Bug 34470
Real Time Holds Queue - make random numbers play nice with forked processes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34470: Initialize random seed after spawning a child worker process
Bug-34470-Initialize-random-seed-after-spawning-a-.patch (text/plain), 2.26 KB, created by
Nick Clemens (kidclamp)
on 2023-08-09 18:13:16 UTC
(
hide
)
Description:
Bug 34470: Initialize random seed after spawning a child worker process
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2023-08-09 18:13:16 UTC
Size:
2.26 KB
patch
obsolete
>From 922f52d80354a8baa4d4fc939a8417ad8de33fca Mon Sep 17 00:00:00 2001 >From: Emily Lamancusa <emily.lamancusa@montgomerycountymd.gov> >Date: Wed, 9 Aug 2023 12:29:35 -0400 >Subject: [PATCH] Bug 34470: Initialize random seed after spawning a child > worker process > >When background_jobs_worker.pl spawns a new child process, it needs to >explicitly reinitialize the random seed - otherwise each child process >will inherit the same random seed from the parent process, and any >randomization will produce identical results each time. > >This patch adds a call to srand immediately after the fork to >reinitialize the seed. Note that child processes should not call >srand with no parameter anywhere else, as the Perl documentation >indicates that srand should not be called with no parameter more than >once per process. > >To test: >1. Apply the logging patch only >2. Set system preferences: > a. RealTimeHoldsQueue -> Enable > b. RandomizeHoldsQueueWeight -> in random order >3. Watch the logs for the staff interface > in ktd: > ktd --shell > koha-intra-err >4. Place a hold. Note that the logs display the branch list before and > after it is randomized. >5. Place some more holds. Note that the branch order after randomization > is identical each time. >6. Apply both patches and restart_all >7. Repeat steps 3-5. > -> Note that the branch order before randomization hasn't changed > -> Note that the branch order after randomization is now different > each time. > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > misc/workers/background_jobs_worker.pl | 2 ++ > 1 file changed, 2 insertions(+) > >diff --git a/misc/workers/background_jobs_worker.pl b/misc/workers/background_jobs_worker.pl >index c54610458f..7d2c4f3876 100755 >--- a/misc/workers/background_jobs_worker.pl >+++ b/misc/workers/background_jobs_worker.pl >@@ -135,6 +135,7 @@ while (1) { > } > > $pm->start and next; >+ srand(); # ensure each child process begins with a new seed > process_job( $job, $args ); > $pm->finish; > >@@ -152,6 +153,7 @@ while (1) { > next unless $args; > > $pm->start and next; >+ srand(); # ensure each child process begins with a new seed > process_job( $job, { job_id => $job->id, %$args } ); > $pm->finish; > >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 34470
:
154219
|
154335
|
154336
| 154339