…ally might occur connecting to a WHOIS server.
This bug is related to issue #40. In fact, the cause of this bug is the workaround introduced in commit ffbbaff to solve the incompatibility with TCPSocket.new when resolv-replace.rb is required and you're trying to pass a nil value as :local_host argument to TCPSocket.new. The workaround was to always default the :local_host to "0.0.0.0", that obviously means localhost. Unfortunately,
This solution works quite well as long as there are not connectivity or server issues. In fact, when for whatever reason "0.0.0.0" can't connect to the remote host, you get an error `Errno::EINVAL: Invalid argument - bind(2)'. Because I don't wont to add extra-complexity when not required, I decided to revert to the original code and default :local_host and :local_port to nil when they are not present. But hey, an other issue is just around the corner!
It turns that resolv-replace.rb tries to resolve the :local_host even if it's nil (ruby bug?) because it checks the existence of any local parameter, regardless you are providing :local_port or local_host.
class TCPSocket < IPSocket
alias original_resolv_initialize initialize
def initialize(host, serv, *rest)
rest = IPSocket.getaddress(rest) unless rest.empty?
original_resolv_initialize(IPSocket.getaddress(host), serv, *rest)
While the following statement is perfectly fine with TCPSocket
TCPSocket.new("whois.nic.it", 43, nil, nil)
it doesn't work when you require resolv-replace.rb.
ArgumentError: cannot interpret as DNS name: nil
from /Users/weppos/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/resolv.rb:1121:in `create'
from /Users/weppos/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/resolv.rb:967:in `generate_candidates'
from /Users/weppos/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/resolv.rb:992:in `resolv'
from /Users/weppos/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/resolv.rb:498:in `each_resource'
from /Users/weppos/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/resolv.rb:391:in `each_address'
from /Users/weppos/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/resolv.rb:115:in `block in each_address'
from /Users/weppos/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/resolv.rb:114:in `each'
from /Users/weppos/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/resolv.rb:114:in `each_address'
from /Users/weppos/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/resolv.rb:92:in `getaddress'
from /Users/weppos/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/resolv.rb:43:in `getaddress'
from /Users/weppos/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/resolv-replace.rb:10:in `getaddress'
from /Users/weppos/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/resolv-replace.rb:22:in `initialize'
At this point, the only solution is to check the :local_host and :local_port parameter and avoid passing them if nil.