Skip to content

[windows][jruby-complete] Resolv.getaddress fails #580

wiibaa opened this Issue Mar 12, 2013 · 2 comments

2 participants

wiibaa commented Mar 12, 2013

Executing the following on windows

java -cp jruby-complete-1.7.3.jar org.jruby.Main -e "require 'resolv'; p Resolv.getaddress('')"

fails with this stacktrace

Errno::ENOENT: No such file or directory - D:/etc/hosts
   initialize at org/jruby/
         open at org/jruby/
         open at org/jruby/
lazy_initialize at jar:file:/D:/temp/jruby-complete-1.7.3.jar!/META-INF/jruby.home/lib/ruby/1.9/resolv.rb:189
  synchronize at org/jruby/ext/thread/
lazy_initialize at jar:file:/D:/temp/jruby-complete-1.7.3.jar!/META-INF/jruby.home/lib/ruby/1.9/resolv.rb:185
 each_address at jar:file:/D:/temp/jruby-complete-1.7.3.jar!/META-INF/jruby.home/lib/ruby/1.9/resolv.rb:236
 each_address at jar:file:/D:/temp/jruby-complete-1.7.3.jar!/META-INF/jruby.home/lib/ruby/1.9/resolv.rb:115
         each at org/jruby/
 each_address at jar:file:/D:/temp/jruby-complete-1.7.3.jar!/META-INF/jruby.home/lib/ruby/1.9/resolv.rb:114
   getaddress at jar:file:/D:/temp/jruby-complete-1.7.3.jar!/META-INF/jruby.home/lib/ruby/1.9/resolv.rb:92
   getaddress at jar:file:/D:/temp/jruby-complete-1.7.3.jar!/META-INF/jruby.home/lib/ruby/1.9/resolv.rb:43
       (root) at -e:1

It seems similar to old closed report JRUBY-3480

JRuby Team member
headius commented Mar 13, 2013

So the issue here is that resolv.rb inludes the following code in its init logic:

  class Hosts
    if /mswin|mingw|bccwin/ =~ RUBY_PLATFORM
      require 'win32/resolv'
      DefaultFileName = Win32::Resolv.get_hosts_path
      DefaultFileName = '/etc/hosts'

On JRuby, RUBY_PLATFORM is always 'java', so this attempts to look for the wrong hosts file.

It does appear that Win32::Resolv.get_hosts_path works on current JRuby:

C:\>jruby -rwin32/resolv -e "puts Win32::Resolv.get_hosts_path"

I will modify resolv.rb to use RbConfig's "host_os" for this check rather than RUBY_PLATFORM.

@headius headius closed this in 9e30eab Mar 14, 2013
JRuby Team member
headius commented Mar 14, 2013

I have made the change to our 1.9 and 2.0 stdlib (1.8 already had it) and filed an issue with MRI to get the change upstreamed:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.