dRuby server crashes when probed on the port its listening on

292 Views Asked by At

I have this test code:

require 'drb/drb'

DRb.start_service(nil, "hello")
puts DRb.uri
DRb.thread.join()

If I then probe the port it grabs using something like nmap, after a few probes, the app crashes.

Under JRuby 1.7, I get this stack:

Errno::ENOPROTOOPT: Protocol not available - Protocol not available
   setsockopt at org/jruby/ext/socket/RubyBasicSocket.java:294
  set_sockopt at /Users/kimptoc/.rvm/rubies/jruby-1.7.3/lib/ruby/1.9/drb/drb.rb:1005
   initialize at /Users/kimptoc/.rvm/rubies/jruby-1.7.3/lib/ruby/1.9/drb/drb.rb:927
       accept at /Users/kimptoc/.rvm/rubies/jruby-1.7.3/lib/ruby/1.9/drb/drb.rb:991
    main_loop at /Users/kimptoc/.rvm/rubies/jruby-1.7.3/lib/ruby/1.9/drb/drb.rb:1615
          run at /Users/kimptoc/.rvm/rubies/jruby-1.7.3/lib/ruby/1.9/drb/drb.rb:1465

Under Ruby 1.9.3-392, the stack is this:

/Users/kimptoc/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/drb/drb.rb:964:in `setsockopt': Invalid argument (Errno::EINVAL)
from /Users/kimptoc/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/drb/drb.rb:964:in `set_sockopt'
from /Users/kimptoc/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/drb/drb.rb:886:in `initialize'
from /Users/kimptoc/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/drb/drb.rb:950:in `new'
from /Users/kimptoc/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/drb/drb.rb:950:in `accept'
from /Users/kimptoc/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/drb/drb.rb:1574:in `main_loop'
from /Users/kimptoc/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/drb/drb.rb:1424:in `block in run'

Is there a way to make dRuby more robust (for example an option or config setting somewhere) and not crash in these situations.

UPDATE

By putting the code in a loop like so, this seems to make it more resilient - but is that best way forward:

while true
  begin
    DRb.start_service("druby://localhost:12345", "hello")
    puts DRb.uri
    DRb.thread.join()
  rescue Exception => e
    puts e.message
  end
end

TIA

0

There are 0 best solutions below