# Ruby bug reading from /dev/urandom after failed require?

**URL:** <https://www.ruby-forum.com/t/ruby-bug-reading-from-dev-urandom-after-failed-require/123951>\
**Category:** Ruby\
**Created:** [December 22, 2007, 4:21pm UTC](https://www.ruby-forum.com/t/ruby-bug-reading-from-dev-urandom-after-failed-require/123951 "2007-12-22T16:21:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![asplake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@asplake](https://www.ruby-forum.com/u/asplake)\
**Post date:** [December 22, 2007, 4:21pm UTC](https://www.ruby-forum.com/t/ruby-bug-reading-from-dev-urandom-after-failed-require/123951/1 "2007-12-22T16:21:11Z")

</div>

I’ve been trying to track down a bug that surfaced when trying to  
generate a Rails 2.0.2 app in Cygwin. Reading from /dev/urandom fails  
with “No such file or directory - /dev/urandom” if a failed require  
has been made previously.

The Rails code looks OK, so I thought it might be Cygwin. I came up  
with a simple snippet that fails in Cygwin (see below). Corinna  
Vinschen over at Cygwin ran strace on it and thought it might be a  
Ruby bug…see her thoughts here:  
[http://cygwin.com/ml/cygwin/2007-12/msg00502.html](http://cygwin.com/ml/cygwin/2007-12/msg00502.html)

I’m not well versed on the low level strace stuff, but I thought I’d  
try to see this through. I’d appreciate any comments from someone  
knowledgeable about the Ruby source.

## Demonstration code:

# Test failure of reading /dev/urandom after failed require

# this method is from the Rails’ source secret\_key\_generator.rb

def generate\_secret\_with\_urandom  
return File.read(“/dev/urandom”, 64).unpack(“H\*”)[0]  
end

cause\_failure = true

begin  
require ‘nonexistent\_file’  
rescue LoadError  
puts ‘’ unless cause\_failure  
end

## puts generate\_secret\_with\_urandom

Thanks,  
Mike B.  
[http://boonedocks.net/mike/](http://boonedocks.net/mike/)

---

<div class="post-metadata">

**Author:** ![asplake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@asplake](https://www.ruby-forum.com/u/asplake)\
**Post date:** [December 22, 2007, 4:47pm UTC](https://www.ruby-forum.com/t/ruby-bug-reading-from-dev-urandom-after-failed-require/123951/2 "2007-12-22T16:47:32Z")

</div>

Hi,

In message “Re: Ruby bug reading from /dev/urandom after failed  
require?”  
on Sun, 23 Dec 2007 00:20:05 +0900, Mike B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:  
|  
|I’ve been trying to track down a bug that surfaced when trying to  
|generate a Rails 2.0.2 app in Cygwin. Reading from /dev/urandom fails  
|with “No such file or directory - /dev/urandom” if a failed require  
|has been made previously.

Could you describe how it fails for those who don’t use Cygwin  
platform, like myself?

|The Rails code looks OK, so I thought it might be Cygwin. I came up  
|with a simple snippet that fails in Cygwin (see below). Corinna  
|Vinschen over at Cygwin ran strace on it and thought it might be a  
|Ruby bug…see her thoughts here:  
|[Corinna Vinschen - Re: Ruby on Rails 2.0.2/Cygwin Bug](http://cygwin.com/ml/cygwin/2007-12/msg00502.html)  
|  
|I’m not well versed on the low level strace stuff, but I thought I’d  
|try to see this through. I’d appreciate any comments from someone  
|knowledgeable about the Ruby source.

The bug must lie between Cygwin and Ruby. We don’t call lseek  
explicitly. You can clearly see this by doing strace on Linux (or  
other platforms), which don’t call lseek at all. So, someone (in the  
library, I guess) must call lseek weirdly on Cygwin.

I have no clue right now to identify “someone”.

```
          matz.

```

---

<div class="post-metadata">

**Author:** ![asplake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@asplake](https://www.ruby-forum.com/u/asplake)\
**Post date:** [January 2, 2008, 10:00pm UTC](https://www.ruby-forum.com/t/ruby-bug-reading-from-dev-urandom-after-failed-require/123951/3 "2008-01-02T22:00:50Z")

</div>

On Dec 22 2007, 10:47 am, Yukihiro M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> The bug must lie between Cygwin and Ruby. We don’t call lseek  
> explicitly. You can clearly see this by doing strace on Linux (or  
> other platforms), which don’t call lseek at all. So, someone (in the  
> library, I guess) must call lseek weirdly on Cygwin.
> 
> I have no clue right now to identify “someone”.

Sorry for the late reply. I have done some more experimentation with  
the Ruby source in Cygwin.

The current Ruby 1.8.6 does not make in Cygwin, giving an error about  
strftime.o. However, the stable-snapshot does make correctly, but my  
test script still gives the /dev/urandom error. Interestingly,  
compiling Ruby 1.9.0 works fine and the /dev/urandom error goes away.

I have GDB on my Cygwin system, but I am not sure where to begin  
tracing the problem. Where would be the best place to set a breakpoint  
for tracking the error “No such file or directory - /dev/urandom”?

Thanks,  
Mike B.  
[http://boonedocks.net/mike/](http://boonedocks.net/mike/)

---

<div class="post-metadata">

**Author:** ![asplake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@asplake](https://www.ruby-forum.com/u/asplake)\
**Post date:** [January 3, 2008, 5:46am UTC](https://www.ruby-forum.com/t/ruby-bug-reading-from-dev-urandom-after-failed-require/123951/4 "2008-01-03T05:46:45Z")

</div>

On Jan 2, 9:39 pm, Nobuyoshi N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Sorry that I missed your post. Fixed it just now.

Excellent! Thank you.

Mike B…

---

<div class="post-metadata">

**Author:** ![asplake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@asplake](https://www.ruby-forum.com/u/asplake)\
**Post date:** [January 3, 2008, 3:39am UTC](https://www.ruby-forum.com/t/ruby-bug-reading-from-dev-urandom-after-failed-require/123951/5 "2008-01-03T03:39:55Z")

</div>

Hi,

At Thu, 3 Jan 2008 06:00:03 +0900,  
Mike B. wrote in [ruby-talk:285706]:

> The current Ruby 1.8.6 does not make in Cygwin, giving an error about  
> strftime.o. However, the stable-snapshot does make correctly, but my  
> test script still gives the /dev/urandom error. Interestingly,  
> compiling Ruby 1.9.0 works fine and the /dev/urandom error goes away.

Sorry that I missed your post. Fixed it just now.

And the make failure is bacause of the change of Cygwin since  
1.8.6 has been released.
