Kernel.srand after_fork

ghazel at ghazel at
Fri Jan 28 05:57:23 EST 2011

On Fri, Jan 28, 2011 at 2:26 AM, Eric Wong <normalperson at> wrote:
> ghazel at wrote:
>> Hi,
>> We recently noticed random numbers from the Unicorn workers were
>> turning up lots of duplicates across requests. Is it possible that the
>> random seed generated when the ruby interpreter starts is duplicated
>> when the workers are forked, and not re-seeded after fork?
>> If so, should I call Kernel.srand in after_fork, or is this something
>> which should be added to Unicorn?
> It looks like a 1.8 bug, which version of Ruby are you running?  Ruby
> 1.9.1 actually had a bug where it was reseeded improperly and led to
> segfaults (see KNOWN_ISSUES).  1.9.2 is fine afaik.

REE 1.8.7

So, calling Kernel.srand in after_fork will fix the 1.8 bug and the
1.9.1 bug and work fine on 1.9.2?


More information about the mongrel-unicorn mailing list