Project

General

Profile

Backport #5661

Segfault in Random.rand with Spork gem

Added by Odaeus (Andrew France) almost 8 years ago. Updated about 7 years ago.

Status:
Closed
Priority:
Normal
[ruby-core:41209]

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 :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)
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.


Files

rspec.saved (263 KB) rspec.saved Segfault output Odaeus (Andrew France), 11/23/2011 03:32 AM
0001-random.c-random_s_rand-avoid-segfault-after-fork-rub.patch (1.89 KB) 0001-random.c-random_s_rand-avoid-segfault-after-fork-rub.patch normalperson (Eric Wong), 11/23/2011 05:45 AM

Related issues

Has duplicate Backport193 - Backport #7159: SIGSEGV when calling Random#rand after forkingClosed10/15/2012Actions

Associated revisions

Revision b87f2fe1
Added by nobu (Nobuyoshi Nakada) over 7 years ago

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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 34977
Added by nobu (Nobuyoshi Nakada) over 7 years ago

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

Revision 34977
Added by nobu (Nobuyoshi Nakada) over 7 years ago

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

Revision 34977
Added by nobu (Nobuyoshi Nakada) over 7 years ago

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

Revision 34977
Added by nobu (Nobuyoshi Nakada) over 7 years ago

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

Revision 34977
Added by nobu (Nobuyoshi Nakada) over 7 years ago

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

Revision 34977
Added by nobu (Nobuyoshi Nakada) over 7 years ago

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

Revision ae5930a8
Added by usa (Usaku NAKAMURA) about 7 years ago

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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@37208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 37208
Added by usa (Usaku NAKAMURA) about 7 years ago

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]

History

Updated by Odaeus (Andrew France) almost 8 years ago

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

Updated by normalperson (Eric Wong) almost 8 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)"

Updated by ko1 (Koichi Sasada) over 7 years ago

  • Category set to core
  • Assignee set to nahi (Hiroshi Nakamura)
#5

Updated by nobu (Nobuyoshi Nakada) over 7 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 (random_s_rand): ensure default PRNG is re-initialized after fork. patched by Eric Wong. [ruby-core:41209][Bug #5661]
#6

Updated by nobu (Nobuyoshi Nakada) about 7 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby master to Backport193
  • Category deleted (core)
  • Status changed from Closed to Assigned
  • Assignee changed from nahi (Hiroshi Nakamura) to usa (Usaku NAKAMURA)
#7

Updated by usa (Usaku NAKAMURA) about 7 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]

Also available in: Atom PDF