Re: [PATCH 1/6] maintenance: add get_random_minute()
From: Derrick Stolee <hidden>
Date: 2023-08-08 19:25:23
On 8/7/2023 5:20 PM, Taylor Blau wrote:
On Mon, Aug 07, 2023 at 06:51:35PM +0000, Derrick Stolee via GitGitGadget wrote:
quoted
+ if (!random_initialized) { + srand((unsigned int)getpid()); + random_initialized = 1; + }I was wondering where else we call srand() within Git, and it looks like the only other spot is in `lock_file_timeout()`. I doubt it, but is there a chance that that code depends on only calling srand() once? I think the answer is "no", since we only use rand() within that function to generate a random-ish backoff period, so I think the repeatability of it doesn't matter all that much.
The main point would be to avoid the cost of spinning up the number generator, but there is potential for a bug if we run both initializers: the lockfile would re-use the same filenames after the generator is reset.
So I think this is kind of outside the scope of your series, but I wonder if we should have a git_rand() that automatically initializes the PRNG with the value of getpid()? Then multiple callers can grab random values at will without reinitializing the PRNG.
I see you're moving ahead with removing the srand() from the lockfile code, so I'll focus on creating a `git_rand()` that centralizes the use of srand(), but won't touch the code in the lockfile so your patch applies independently. Thanks, -Stolee