Skip to content

Commit c721203

Browse files
evanphxdrbrain
authored andcommitted
Protect the require code
This has a potential issue in that it will serialize much more code than MRI does because the first thread to hit this require method will hold all other threads doing a require until the first require returns. MRI's locking does not lock the full downstream code path.
1 parent 8a45dce commit c721203

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/rubygems/core_ext/kernel_require.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# See LICENSE.txt for permissions.
55
#++
66

7+
require 'monitor'
8+
79
module Kernel
810

911
if defined?(gem_original_require) then
@@ -31,7 +33,11 @@ module Kernel
3133
# The normal <tt>require</tt> functionality of returning false if
3234
# that file has already been loaded is preserved.
3335

36+
ACTIVATION_MONITOR = Monitor.new
37+
3438
def require path
39+
ACTIVATION_MONITOR.enter
40+
3541
spec = Gem.find_unresolved_default_spec(path)
3642
if spec
3743
Gem.remove_unresolved_default_spec(spec)
@@ -111,6 +117,8 @@ def require path
111117
end
112118

113119
raise load_error
120+
ensure
121+
ACTIVATION_MONITOR.exit
114122
end
115123

116124
private :require

0 commit comments

Comments
 (0)