Issue Details (XML | Word | Printable)

Key: JRUBY-2347
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: MenTaLguY
Reporter: Vladimir Sizikov
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
JRuby

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

Created: 31/Mar/08 11:25 AM   Updated: 04/Jul/08 09:07 AM
Component/s: Core Classes/Modules
Affects Version/s: JRuby 1.1
Fix Version/s: JRuby 1.1.2

Time Tracking:
Not Specified

Environment: Latest JRuby 1.1 from trunk.


 Description  « Hide
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.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
MenTaLguY added a comment - 03/May/08 10:53 PM
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.