Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10544 (closed defect: invalid)

Opened 2 years ago

Last modified 2 years ago

Rails' use of /dev/urandom fails in Cygwin

Reported by: boone Assigned to: core
Priority: normal Milestone: 2.x
Component: Railties Version: edge
Severity: minor Keywords: cygwin urandom secret_key_generator
Cc:

Description

Trying to create a Rails 2.0.2 application in Cygwin fails with this error:

No such file or directory - /dev/urandom

The problem appears to be caused at line 86 in secret_key_generator.rb: http://dev.rubyonrails.org/browser/tags/rel_2-0-2/railties/lib/rails_generator/secret_key_generator.rb#L86

Other users have also experienced the problem: http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/0a371707459f2b8e/c219c93a3a5fc017

Strangely if you add a puts statement just above line 86, as suggested by Marcin Jekot in the Google Groups post, the code will run fine.

Not sure if we should blame this on Cygwin or if it's something that should be modified in Rails.

Attachments

urandom_test.rb (362 bytes) - added by boone on 12/22/07 03:20:46.
Simple Example of /dev/urandom failure in Cygwin

Change History

12/21/07 18:50:38 changed by boone

I also brought this up on the Cygwin mailing list: http://cygwin.com/ml/cygwin/2007-12/threads.html#00463

They suggested running strace on the rails app creation. I did so but I really don't follow the strace output enough to know what to look for. I made a diff of the /dev/urandom section of the strace output from the failing version and the working version (with the puts statement). That output is posted here: http://cygwin.com/ml/cygwin/2007-12/msg00482.html

12/22/07 02:37:40 changed by boone

  • keywords changed from cygwin urandom to cygwin urandom secret_key_generator.

Some more experimentation:

The error looks to be connected to the failure of the code to require 'securerandom' It's almost as if the file not found exception carries over from the self.supports_securerandom? method to the attempt to get data from /dev/urandom. No idea why that happens.

If remove securerandom from the generators list, or move it after urandom, the urandom works fine:

GENERATORS = [ :urandom, :secure_random, :win32_api, :openssl, :prng ].freeze

Alternately, you can force the self.supports_securerandom? to return false and the urandom works again. That's what leads me to think that require 'securerandom' is causing this somehow.

BTW, my Cygwin Ruby version is "ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-cygwin]".

12/22/07 03:20:46 changed by boone

  • attachment urandom_test.rb added.

Simple Example of /dev/urandom failure in Cygwin

12/22/07 03:22:50 changed by boone

I added the attachment urandom_test.rb. This file will fail in my version of Cygwin (and likely for the others who noted the problem). It's looking like a Cygwin problem rather than something to blame Rails for.

12/22/07 04:09:47 changed by matt

  • status changed from new to closed.
  • resolution set to invalid.

Thanks for the test but this really looks like a Cygwin problem.

01/03/08 04:49:34 changed by boone

Just an update for anyone who might experience this problem.

This turned out to be a bug in Ruby. It has been patched, and it seems to correct the problem in my test script, and likely Rails as well.

http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/io.c?r1=13774&r2=14858

Not sure how long this will take to make it to Cygwin's Ruby package though.