ruby-changes:56709
From: Benoit <ko1@a...>
Date: Wed, 31 Jul 2019 09:25:06 +0900 (JST)
Subject: [ruby-changes:56709] Benoit Daloze: 2453d16f5e (master): [rubygems/rubygems] Synchronize access to the Gem::Specification::LOAD_CACHE Hash
https://git.ruby-lang.org/ruby.git/commit/?id=2453d16f5e From 2453d16f5e44f67a50e1be9b08504a14960610ef Mon Sep 17 00:00:00 2001 From: Benoit Daloze <eregontp@g...> Date: Thu, 6 Jun 2019 15:52:44 +0200 Subject: [rubygems/rubygems] Synchronize access to the Gem::Specification::LOAD_CACHE Hash * It's accessed concurrently, notably when installing a gem with a C extension. https://github.com/rubygems/rubygems/commit/543294d7dd diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 88e30e7..abb6e0e 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -109,6 +109,7 @@ class Gem::Specification < Gem::BasicSpecification https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L109 # rubocop:disable Style/MutableConstant LOAD_CACHE = {} # :nodoc: # rubocop:enable Style/MutableConstant + LOAD_CACHE_MUTEX = Mutex.new private_constant :LOAD_CACHE if defined? private_constant @@ -753,7 +754,9 @@ class Gem::Specification < Gem::BasicSpecification https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L754 end def self._clear_load_cache # :nodoc: - LOAD_CACHE.clear + LOAD_CACHE_MUTEX.synchronize do + LOAD_CACHE.clear + end end def self.each_gemspec(dirs) # :nodoc: @@ -1105,7 +1108,7 @@ class Gem::Specification < Gem::BasicSpecification https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L1108 def self.load(file) return unless file - _spec = LOAD_CACHE[file] + _spec = LOAD_CACHE_MUTEX.synchronize { LOAD_CACHE[file] } return _spec if _spec file = file.dup.untaint @@ -1120,7 +1123,9 @@ class Gem::Specification < Gem::BasicSpecification https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L1123 if Gem::Specification === _spec _spec.loaded_from = File.expand_path file.to_s - LOAD_CACHE[file] = _spec + LOAD_CACHE_MUTEX.synchronize do + LOAD_CACHE[file] = _spec + end return _spec end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/