[Rubygems-developers] [ rubygems-Bugs-28561 ] Doesn't check that the current thread already has the mutex in Gem.searcher

noreply at rubyforge.org noreply at rubyforge.org
Sat Nov 13 04:31:26 EST 2010


Bugs item #28561, was opened at 2010-09-12 17:27
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=575&aid=28561&group_id=126

Category: #gem and #require methods
Group: None
>Status: Closed
>Resolution: Accepted
Priority: 3
Submitted By: Jeremy Evans (jeremyevans)
Assigned to: James Tucker (raggi)
Summary: Doesn't check that the current thread already has the mutex in Gem.searcher

Initial Comment:
Gem.search doesn't check that the current thread already has the mutex.  In certain cases, it's possible that it will call itself when it already has the mutex.  See http://github.com/jeremyevans/home_run/issues/issue/13.

For example, this backtrace shows that searcher can call itself recursively (see ****):

C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:840:in `synchronize': thread 0x4394f10 tried to join itself (ThreadError)
****from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:840:in `searcher'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:34:in `require'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/date.rb:2
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from C:/Ruby187/lib/ruby/1.8/yaml/rubytypes.rb:2
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from C:/Ruby187/lib/ruby/1.8/yaml.rb:396
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/config_file.rb:220:in `load_file'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/config_file.rb:168:in `initialize'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:385:in `new'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:385:in `configuration'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:635:in `path'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:68:in `installed_spec_directories'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:58:in `from_installed_gems'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:883:in `source_index'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/gem_path_searcher.rb:81:in `init_gemspecs'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/gem_path_searcher.rb:13:in `initialize'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:841:in `new'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:841:in `searcher'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:840:in `synchronize'
****from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:840:in `searcher'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:479:in `find_files'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:983:in `load_plugins'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:1139
    from ./script/../config/boot.rb:90:in `require'
    from ./script/../config/boot.rb:90:in `load_rubygems'
    from ./script/../config/boot.rb:53:in `load_initializer'
    from ./script/../config/boot.rb:38:in `run'
    from ./script/../config/boot.rb:11:in `boot!'
    from ./script/../config/boot.rb:114
    from script/console:2:in `require'
    from script/console:2

You can prevent this by checking if current thread already has the mutex, and not doing MUTEX.synchronize if so.

----------------------------------------------------------------------

>Comment By: James Tucker (raggi)
Date: 2010-11-13 09:31

Message:
Merged.

----------------------------------------------------------------------

Comment By: James Tucker (raggi)
Date: 2010-09-12 18:04

Message:
The following should be cherry picked into master at the appropriate time.

http://github.com/rubygems/rubygems/commit/cceab040bde07d567131ccea2bc707a1f7dd7c8b

We're not thread safe, this mutex is pointless and incorrect.

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=575&aid=28561&group_id=126


More information about the Rubygems-developers mailing list