Skip to content

Fix DNS resolution randomly failing#41

Closed
grogers0 wants to merge 1 commit intojruby:masterfrom
grogers0:master
Closed

Fix DNS resolution randomly failing#41
grogers0 wants to merge 1 commit intojruby:masterfrom
grogers0:master

Conversation

@grogers0
Copy link

When resolving DNS, the current code picks a random udp port and tries to bind to it to use for the DNS request. If the port it chooses is already in use, a SocketError is raised (Unlike in regular Ruby where Errno::EADDRINUSE is raised, and a new random port is chosen). Fix by letting the OS choose a random port that is not in use for us.

@BanzaiMan
Copy link
Member

Hi there.

This is an issue with the MRI standard library. As such, please take up the issue to the core team. http://redmine.ruby-lang.org/

@BanzaiMan BanzaiMan closed this Jun 25, 2011
@LeeXGreen
Copy link

I'm not sure this is an issue with the MRI library -- the SocketError comes from JRuby's socket implementation :(

Anyway, I monkey-patched this one for myself by rescuing the SocketError when it could not bind.

@LeeXGreen
Copy link

jruby-1.7.9 :002 > require 'socket'
=> true
jruby-1.7.9 :003 > u = UDPSocket.new
=> #<UDPSocket:fd 616>
jruby-1.7.9 :004 > u2 = UDPSocket.new
=> #<UDPSocket:fd 617>
jruby-1.7.9 :005 > u.bind('0.0.0.0', 1100)
=> 0
jruby-1.7.9 :006 > u2.bind('0.0.0.0', 1100)
SocketError: bind: name or service not known
from org/jruby/ext/socket/RubyUDPSocket.java:160:in bind' from (irb):6:inevaluate'
from org/jruby/RubyKernel.java:1119:in eval' from org/jruby/RubyKernel.java:1519:inloop'
from org/jruby/RubyKernel.java:1282:in catch' from org/jruby/RubyKernel.java:1282:incatch'
from /Users/leeg/.rvm/rubies/jruby-1.7.9/bin/irb:13:in `(root)'

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

Successfully merging this pull request may close these issues.

3 participants