Forum: Ruby-core [ruby-trunk - Bug #7159][Open] SIGSEGV when calling Random#rand after forking

Posted by "kris7t (Kristóf Marussy)" <kris7topher@gmail.com> (Guest)
on 2012-10-14 18:43
(Received via mailing list)
Issue #7159 has been reported by kris7t (Kristóf Marussy).

----------------------------------------
Bug #7159: SIGSEGV when calling Random#rand after forking
https://bugs.ruby-lang.org/issues/7159

Author: kris7t (Kristóf Marussy)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: 1.9.3p194


When Kernel#fork is called,
Ruby uninitializes the default random generator Random::DEFAULT
by setting the next field of the struct MT that provides its state to 0.

Kernel#rand correctly initializes this random generator by a seed
when it detects this.
However, Random#rand does not do this and therefore attempting to
call Random#rand in a newly forked child process results in a
segmentation fault, because a null pointer is being dereferenced.

This irb session illustrates the problem:
https://gist.github.com/3888930
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.