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

                 Key: JRUBY-2347
                 URL: http://jira.codehaus.org/browse/JRUBY-2347
             Project: JRuby
          Issue Type: Bug
          Components: Core Classes/Modules
    Affects Versions: JRuby 1.1
         Environment: Latest JRuby 1.1 from trunk.
            Reporter: Vladimir Sizikov


The following example:

{noformat}
require 'drb'

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

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.




-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to