[Koha-bugs] [Bug 34470] Real Time Holds Queue - make random numbers play nice with forked processes

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Thu Aug 3 16:46:19 CEST 2023


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34470

--- Comment #3 from Emily Lamancusa <emily.lamancusa at montgomerycountymd.gov> ---
The logging makes it clear that the call to shuffle() in
load_branches_to_pull_from is "randomizing" deterministically for some reason.
According to the List::Utils docs, shuffle() depends on Perl's rand() function
(unless an alternative method is set).

I think the bug has to do with the scenario described here:
https://stackoverflow.com/questions/58120618/how-to-get-random-number-in-forked-processes

We do fork at minimum one process to process a background job (or more
depending on configuration after bug 32558). According to the above, if a
parent process uses rand() and later spawns a child process which also calls
rand(), every child process will inherit the same seed and thus produce an
identical random number sequence unless the seed is reset with srand() after
the fork.

The official docs for rand() don't quite spell this out but they allude to the
need to call srand() in a child process (though they also warn that srand()
should not be called more than once per process).

The results I'm seeing are consistent with this, and that would also explain
why this doesn't happen in the cron job (which does not fork).

-- 
You are receiving this mail because:
You are the assignee for the bug.
You are watching all bug changes.


More information about the Koha-bugs mailing list