Skip to content

DNS resolution fails with Linux JRE #1286

@tailrecur

Description

@tailrecur

DNS lookup in JRuby of an MX record for a domain fails consistently on our production servers. But the same lookup works in MRI ruby. See shell output below:

lewis@shell01:~/jruby-1.7.8$ bin/jruby -v
jruby 1.7.8 (1.9.3p392) 2013-11-14 0ce429e on Java HotSpot(TM) 64-Bit Server VM 1.7.0_45-b18 [linux-amd64]
lewis@shell01:~/jruby-1.7.8$
lewis@shell01:~/jruby-1.7.8$ bin/jruby -e "require 'resolv'; puts Resolv::DNS.new.getresources(\"google.com\", Resolv::DNS::Resource::IN::MX).inspect"
SocketError: bind: name or service not known
                bind at org/jruby/ext/socket/RubyUDPSocket.java:160
    bind_random_port at /home/lewis/jruby-1.7.8/lib/ruby/1.9/resolv.rb:637
          initialize at /home/lewis/jruby-1.7.8/lib/ruby/1.9/resolv.rb:718
                each at org/jruby/RubyArray.java:1613
          initialize at /home/lewis/jruby-1.7.8/lib/ruby/1.9/resolv.rb:706
  make_udp_requester at /home/lewis/jruby-1.7.8/lib/ruby/1.9/resolv.rb:544
       each_resource at /home/lewis/jruby-1.7.8/lib/ruby/1.9/resolv.rb:500
        getresources at /home/lewis/jruby-1.7.8/lib/ruby/1.9/resolv.rb:490
              (root) at -e:1
lewis@shell01:~/jruby-1.7.8$
lewis@shell01:~/jruby-1.7.8$
lewis@shell01:~/jruby-1.7.8$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
lewis@shell01:~/jruby-1.7.8$ ruby -e "require 'resolv'; puts Resolv::DNS.new.getresources(\"google.com\", Resolv::DNS::Resource::IN::MX).inspect"
[#<Resolv::DNS::Resource::IN::MX:0x00000001d56d98 @preference=30, @exchange=#<Resolv::DNS::Name: alt2.aspmx.l.google.com.>, @ttl=600>, #<Resolv::DNS::Resource::IN::MX:0x00000001d55d58 @preference=20, @exchange=#<Resolv::DNS::Name: alt1.aspmx.l.google.com.>, @ttl=600>]

I have tried this with JRE6 and JRE7 and get the same error.
This code works on my laptop which runs the Apple JRE.

I suspect that the DNS lookup code cannot bind to a socket for some reason and raises a misleading error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions