Project

General

Profile

Actions

Bug #12139

closed

return OpenSSL::Random.random_bytes(n) call takes to long. OpenSSL:: bug on windows.

Added by Justin (Justin Ward) about 8 years ago. Updated almost 8 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:74105]

Description

I have been a windows dev for a while now. I have never solved this rails startup issue. Running one Rspec test takes rails 22 seconds to load on my PC. When I (temporarily) comment out the line in securerandom.rb and replace it with a hardcoded return the startup time is reduced to 10 seconds.

#return OpenSSL::Random.random_bytes(n)
return "\xD3\x04F\f0\xD6{G\xB9\x81"

I can duplicate this on a windows 7 and windows 10 PC.

I have the lastest version of OpenSSL (1.02) installed.

Tickets like this have been reported before, but they get closed without being solved for unknown reasons. Please share the joy of Ruby with us PC users :).
See this more more info: http://stackoverflow.com/questions/29984838/openssl-causing-very-slow-rails-boot-time-on-windows/35749120#35749120

Updated by nobu (Nobuyoshi Nakada) about 8 years ago

  • Status changed from Open to Feedback

Maybe the entropy pool exhausted?
Does moving mouse or typing keyboard wake up OpenSSL?

Updated by nobu (Nobuyoshi Nakada) about 8 years ago

  • Description updated (diff)

Updated by naruse (Yui NARUSE) about 8 years ago

Your issue sounds related with https://wiki.openssl.org/index.php/Random_Numbers#Windows_Issues
But Bug 2100 the heap walk issue is closed.

Anyway maybe SecureRandom, RSpec actually calls, should use CryptGenRandom instead of openssl.

Updated by Justin (Justin Ward) about 8 years ago

Nobuyoshi Nakada wrote:

Maybe the entropy pool exhausted?
Does moving mouse or typing keyboard wake up OpenSSL?

In the 22 seconds it takes rails to load i am usually writing code, so OpenSSL does not get woken up by keyboard or mouse activity.

Updated by Justin (Justin Ward) about 8 years ago

Yui NARUSE wrote:

Your issue sounds related with https://wiki.openssl.org/index.php/Random_Numbers#Windows_Issues
But Bug 2100 the heap walk issue is closed.

Anyway maybe SecureRandom, RSpec actually calls, should use CryptGenRandom instead of openssl.

CryptGenRandom would be an excellent solution in my opinion :)

Updated by usa (Usaku NAKAMURA) about 8 years ago

Random.raw_seed is an alternative to OpenSSL::Random.random_seed.
This calls CryptGenRandom internally.

BTW, I could not reproduce the problem on my environment (x64-mswin64, Win7, OpenSSL 1.0.2f).
Calling OpenSSL::Random.random_bytes 10,000,000 times takes about 11 seconds, but I think it's not so slow.
Calling Random.raw_seed is a little faster, but only 6.7%.

D:\ruby> ruby -ropenssl -e"t = Time.now; 10_000_000.times{}; p Time.now - t"
0.541031

D:\ruby> ruby -ropenssl -e"t = Time.now; 10_000_000.times{OpenSSL::Random.random_bytes(16)}; p Time.now - t"
11.243643

D:\ruby> ruby -e"t = Time.now; 10_000_000.times{Random.raw_seed(16)}; p Time.now - t"
10.533603

Updated by usa (Usaku NAKAMURA) about 8 years ago

Sorry, I've forgotten to note that Random.raw_seed is Ruby 2.3 feature.

Actions #8

Updated by naruse (Yui NARUSE) about 8 years ago

  • Status changed from Feedback to Closed

Applied in changeset r54144.


Updated by usa (Usaku NAKAMURA) almost 8 years ago

  • Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.1: WONTFIX, 2.2: REQUIRED, 2.3: REQUIRED

Updated by usa (Usaku NAKAMURA) almost 8 years ago

  • Backport changed from 2.1: WONTFIX, 2.2: REQUIRED, 2.3: REQUIRED to 2.1: WONTFIX, 2.2: DONE, 2.3: REQUIRED

ruby_2_2 r54693 merged revision(s) 54144.

Updated by nagachika (Tomoyuki Chikanaga) almost 8 years ago

  • Backport changed from 2.1: WONTFIX, 2.2: DONE, 2.3: REQUIRED to 2.1: WONTFIX, 2.2: DONE, 2.3: DONE

ruby_2_3 r54713 merged revision(s) 54144,54699.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0