Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

wiibaa opened this issue Mar 12, 2013 · 2 comments

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

wiibaa opened this issue Mar 12, 2013 · 2 comments


Copy link

@wiibaa 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

Copy link

@headius 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
Copy link

@headius 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
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.