JRuby

Race condition in DRb: Socket not always closed in DRb.stop_service

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: JRuby 1.1
  • Fix Version/s: JRuby 1.1.2
  • Component/s: Core Classes/Modules
  • Labels:
    None
  • Environment:
    Latest JRuby 1.1 from trunk.
  • Number of attachments :
    0

Description

The following example:

require 'drb'

5.times {
  DRb.start_service('druby://localhost:9001')
  DRb.stop_service
}

Produces the following exception in JRuby:
/opt/work/jruby.git/lib/ruby/1.8/drb/drb.rb:865:in `new': Address already in use - Address in use (Errno::EADDRINUSE)
from /opt/work/jruby.git/lib/ruby/1.8/drb/drb.rb:865:in `open'
from /opt/work/jruby.git/lib/ruby/1.8/drb/drb.rb:865:in `open_server'
from /opt/work/jruby.git/lib/ruby/1.8/drb/drb.rb:759:in `open_server'
from /opt/work/jruby.git/lib/ruby/1.8/drb/drb.rb:757:in `each'
from /opt/work/jruby.git/lib/ruby/1.8/drb/drb.rb:757:in `open_server'
from /opt/work/jruby.git/lib/ruby/1.8/drb/drb.rb:1339:in `initialize'
from /opt/work/jruby.git/lib/ruby/1.8/drb/drb.rb:1628:in `new'
from /opt/work/jruby.git/lib/ruby/1.8/drb/drb.rb:1628:in `start_service'
from test-drb.rb:4
from test-drb.rb:3:in `times'
from test-drb.rb:3

After some investigation it seems that the flaw is in the DRb itself, and simple
addition of sleep 1 in lib/ruby/1.8/drb/drb.rb, in method run (line 1428), leads to the same exception even in MRI.

Basically, a new Thread is being started in the run method, it has begin-ensure block, but in case when a thread is started but not yet entered begin-ensure, an attempt to stop the service and to kill the thread leads to situation when ensure block is not executed, and the following satement is not being run: @protocol.close if @protocol

Hence, the port is not being freed.

This leads to some rubyspec failures, since the specs exhibit exactly this behavior, starting and stopping the DRb service quickly.

Activity

Hide
MenTaLguY added a comment -

This should be resolved in r6623, in which I tried to resolve a number of concurrency problems with DRb (though there are still a lot to go). The new code uses a more gentle approach than Thread#kill.

Show
MenTaLguY added a comment - This should be resolved in r6623, in which I tried to resolve a number of concurrency problems with DRb (though there are still a lot to go). The new code uses a more gentle approach than Thread#kill.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: