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

resolv-replace.rb is failing when given an IPv6 address URI #3336

Open
zaccari opened this issue Sep 16, 2015 · 1 comment
Open

resolv-replace.rb is failing when given an IPv6 address URI #3336

zaccari opened this issue Sep 16, 2015 · 1 comment

Comments

@zaccari
Copy link

zaccari commented Sep 16, 2015

We've got a tool that sends HTTP commands to network devices via their IPv6 address, using the http.rb gem. Things worked as expected until we required resolv-replace.rb to improve proxy support for another feature of our rails application. It looks like by requiring this file in one section, all sockets are injected with the resolver.

Example:

irb(main):012:0> HTTP.get('https://[2620:000e:4000:8890:0000:0000:0101:408a]:443/cgi-bin/test')
SocketError: Hostname not known: [2620:000e:4000:8890:0000:0000:0101:408a]
  from /opt/torquebox/jruby/lib/ruby/1.9/resolv-replace.rb:13:in `getaddress'
  from /opt/torquebox/jruby/lib/ruby/1.9/resolv-replace.rb:24:in `initialize'
  from org/jruby/RubyIO.java:1177:in `open'
  from /opt/rails/vendor/bundle/jruby/1.9/gems/http-0.8.12/lib/http/timeout/null.rb:18:in `connect'
  from /opt/rails/vendor/bundle/jruby/1.9/gems/http-0.8.12/lib/http/connection.rb:33:in `initialize'
  from /opt/rails/vendor/bundle/jruby/1.9/gems/http-0.8.12/lib/http/client.rb:65:in `make_request'
  from /opt/rails/vendor/bundle/jruby/1.9/gems/http-0.8.12/lib/http/client.rb:51:in `perform'
  from /opt/rails/vendor/bundle/jruby/1.9/gems/http-0.8.12/lib/http/cache/null_cache.rb:9:in `perform'
  from /opt/rails/vendor/bundle/jruby/1.9/gems/http-0.8.12/lib/http/client.rb:50:in `perform'
  from /opt/rails/vendor/bundle/jruby/1.9/gems/http-0.8.12/lib/http/client.rb:39:in `request'
  from /opt/rails/vendor/bundle/jruby/1.9/gems/http-0.8.12/lib/http/chainable.rb:18:in `get'
  from (irb):14:in `evaluate'
  from org/jruby/RubyKernel.java:1101:in `eval'
  from org/jruby/RubyKernel.java:1501:in `loop'
  from org/jruby/RubyKernel.java:1264:in `catch'
  from org/jruby/RubyKernel.java:1264:in `catch'
  from /opt/rails/vendor/bundle/jruby/1.9/gems/railties-3.2.22/lib/rails/commands/console.rb:47:in `start'
  from /opt/rails/vendor/bundle/jruby/1.9/gems/railties-3.2.22/lib/rails/commands/console.rb:8:in `start'
  from /opt/rails/vendor/bundle/jruby/1.9/gems/railties-3.2.22/lib/rails/commands.rb:41:in `(root)'
  from org/jruby/RubyKernel.java:1065:in `require'
  from script/rails:6:in `(root)'irb(main):015:0

We were able to fix the error by updating resolv-replace.rb with the following:

class << IPSocket
  # :stopdoc:
  alias original_resolv_getaddress getaddress
  # :startdoc:
  def getaddress(host)
    #
    # Start fix
    #
    # Strip brackets from IPv6 addresses
    #
    host = host.to_s.gsub(/\[|\]/, '')
    #
    # End fix
    #
    begin
      return Resolv.getaddress(host).to_s
    rescue Resolv::ResolvError
      raise SocketError, "Hostname not known: #{host}"
    end
  end
end

Definition is here for reference.

One possible solution we have is to use DNS to resolve the address of a device, but that will take some time to implement. Is there anything we can do in the short term aside from updating this file? Any help on the matter is much appreciated.

@zaccari
Copy link
Author

zaccari commented Jan 11, 2016

Any updates/comments on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant