Segfault in Random.rand with Spork gem
When running my Rails 3.1 RSpec suite with the Spork gem I get a Segmentation Fault caused by the Random.rand method.
The full debug output is attached. Sorry I have not been able to isolate the code to a minimum test case. Suggestions on reproducing with less code would be welcome.
The offending code is in a Factory Girl factory definition:
trait :with_messages do
after_create do |mt|
user = FactoryGirl.create(:user) # To prevent creating 1 user per message
FactoryGirl.create_list(:message, 1 + Random.rand(4), thread: mt, created_by: user)
Spork is loaded with: bundle exec spork rspec
The fault occurs when the test run is executed with: bundle exec rspec spec
It works fine when not running in the Spork process.
Updated by normalperson (Eric Wong) over 10 years ago
- File 0001-random.c-random_s_rand-avoid-segfault-after-fork-rub.patch 0001-random.c-random_s_rand-avoid-segfault-after-fork-rub.patch added
Attached patch should fix it (test cases included).
git users: git pull git://bogomips.org/ruby.git random-fork
Until the next Ruby release, Spork can workaround this by using
"rand(4)" instead of "Random.rand(4)"
Updated by nobu (Nobuyoshi Nakada) about 10 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
Updated by usa (Usaku NAKAMURA) over 9 years ago
- Status changed from Assigned to Closed
This issue was solved with changeset r37208.
Andrew, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
merge revision(s) 34977: [Backport #5661]
* random.c (random_s_rand): ensure default PRNG is re-initialized after fork. patched by Eric Wong. [ruby-core:41209][Bug #5661]