Backport #5661

Segfault in Random.rand with Spork gem

Added by Andrew France over 2 years ago. Updated over 1 year ago.

[ruby-core:41209]
Status:Closed
Priority:Normal
Assignee:Usaku NAKAMURA

Description

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 :withmessages do
after
create do |mt|
user = FactoryGirl.create(:user) # To prevent creating 1 user per message
FactoryGirl.createlist(:message, 1 + Random.rand(4), thread: mt, createdby: user)
end
end

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.

rspec.saved - Segfault output (263 KB) Andrew France, 11/23/2011 03:32 AM

0001-random.c-random_s_rand-avoid-segfault-after-fork-rub.patch Magnifier (1.89 KB) Eric Wong, 11/23/2011 05:45 AM


Related issues

Duplicated by Backport93 - Backport #7159: SIGSEGV when calling Random#rand after forking Closed 10/15/2012

Associated revisions

Revision 37208
Added by Usaku NAKAMURA over 1 year ago

merge revision(s) 34977: [Backport #5661]

* random.c (random_s_rand): ensure default PRNG is re-initialized
  after fork.  patched by Eric Wong.  [Bug #5661]

History

#1 Updated by Andrew France over 2 years ago

Sigh, sorry I appear to have used a bad formatter code and can't edit the ticket.

#2 Updated by Eric Wong over 2 years ago

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)"

#3 Updated by Hiroshi Nakamura over 2 years ago

formatting

#4 Updated by Koichi Sasada about 2 years ago

  • Category set to core
  • Assignee set to Hiroshi Nakamura

#5 Updated by Nobuyoshi Nakada about 2 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r34977.
Andrew, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • random.c (randomsrand): ensure default PRNG is re-initialized after fork. patched by Eric Wong. [Bug #5661]

#6 Updated by Nobuyoshi Nakada over 1 year ago

  • Tracker changed from Bug to Backport
  • Project changed from ruby-trunk to Backport93
  • Category deleted (core)
  • Status changed from Closed to Assigned
  • Assignee changed from Hiroshi Nakamura to Usaku NAKAMURA

#7 Updated by Usaku NAKAMURA over 1 year 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.  [Bug #5661]

Also available in: Atom PDF