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

Closed
wiibaa opened this Issue Mar 12, 2013 · 2 comments

Comments

Projects
None yet
2 participants
@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('www.google.com')"

fails with this stacktrace

Errno::ENOENT: No such file or directory - D:/etc/hosts
   initialize at org/jruby/RubyFile.java:333
         open at org/jruby/RubyIO.java:1179
         open at org/jruby/RubyKernel.java:333
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/Mutex.java:149
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/RubyArray.java:1613
 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

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius Mar 13, 2013

Member

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
    else
      DefaultFileName = '/etc/hosts'
    end

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"
C:/WINDOWS/System32/drivers/etc/hosts

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

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
    else
      DefaultFileName = '/etc/hosts'
    end

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"
C:/WINDOWS/System32/drivers/etc/hosts

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

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius Mar 14, 2013

Member

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: https://bugs.ruby-lang.org/issues/8090

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: https://bugs.ruby-lang.org/issues/8090

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment