JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-3812

Socket::gethostbyname does reverse DNS lookup for IP address and is slow if no DNS reverse lookup reply is received

    Details

    • Patch Submitted:
      Yes
    • Number of attachments :
      1

      Description

      Socket::gethostbyname(host_name) finds IP address of host_name and then does reverse DNS lookup for IP address (was traced down using tcpdump on Mac OS X).
      If DNS server is not returning reverse DNS name for IP adress, then this method on Mac OS X took about 20 seconds.

      Discussed with headius on IRC and here are potential reasons:
      headius:http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6413593
      headius: it seems that it's not our call to getByName, but a subsequent call to getCanonicalHostName that does it

      On MRI it is not doing reverse DNS lookup and always is very fast.

      Socket::gethostbyname(Socket::gethostname) call is used in DataObjects drivers and as a result on some machines loading DataObjects JDBC driver could take very long time.

      1. jruby-3812.patch
        4 kB
        Charles Oliver Nutter

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        The problem here is that whenever we look up an InetAddress, we build our structure for Ruby with a call to getCanonicalName. But because InetAddress instances are getting created without a name (because they're from the result of an IP lookup) there's no name to return. This results in InetAddress doing a second reverse lookup to turn the IP address back into a name.

        We need a better way to get InetAddress and the appropriate hostname (canonical or otherwise) without doing the extra lookup.

        Show
        Charles Oliver Nutter added a comment - The problem here is that whenever we look up an InetAddress, we build our structure for Ruby with a call to getCanonicalName. But because InetAddress instances are getting created without a name (because they're from the result of an IP lookup) there's no name to return. This results in InetAddress doing a second reverse lookup to turn the IP address back into a name. We need a better way to get InetAddress and the appropriate hostname (canonical or otherwise) without doing the extra lookup.
        Hide
        Charles Oliver Nutter added a comment -

        Here's a patch that eliminates the extra calls to getCanonicalHostName as much as possible. This should in theory eliminate the reverse lookups...but does it break something else? Is there a reason we need to get the actual host name or is it ok to use the given name that was successfully looked up?

        I'd appreciate some other eyes on this. It passes all tests, but I would like some other opinions.

        Show
        Charles Oliver Nutter added a comment - Here's a patch that eliminates the extra calls to getCanonicalHostName as much as possible. This should in theory eliminate the reverse lookups...but does it break something else? Is there a reason we need to get the actual host name or is it ok to use the given name that was successfully looked up? I'd appreciate some other eyes on this. It passes all tests, but I would like some other opinions.
        Hide
        Thomas E Enebo added a comment -

        Not making 1.4...

        Show
        Thomas E Enebo added a comment - Not making 1.4...
        Hide
        Charles Oliver Nutter added a comment -

        At some point we modified logic to only use canonical host name if Ruby is set up to do reverse lookups. Ruby 1.9 mode is set to not reverse by default, and 1.7 starts up in 1.9 mode by default, so I'll call this fixed in 1.7.

        Show
        Charles Oliver Nutter added a comment - At some point we modified logic to only use canonical host name if Ruby is set up to do reverse lookups. Ruby 1.9 mode is set to not reverse by default, and 1.7 starts up in 1.9 mode by default, so I'll call this fixed in 1.7.

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Raimonds Simanovskis
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: