1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Rely on the load interlock for non-caching reloads, too

This commit is contained in:
Matthew Draper 2014-09-30 01:46:07 +09:30
parent c37d47e308
commit 383fed5f23
4 changed files with 28 additions and 24 deletions

View file

@ -13,6 +13,16 @@ module ActiveSupport
end
end
# Attempt to obtain a "loading" (exclusive) lock. If possible,
# execute the supplied block while holding the lock. If there is
# concurrent activity, return immediately (without executing the
# block) instead of waiting.
def attempt_loading
@lock.exclusive(true) do
yield
end
end
def start_running
@lock.start_sharing
end

View file

@ -32,26 +32,18 @@ module Rails
middleware.use ::Rack::Lock
elsif config.allow_concurrency
# Do nothing, even if we know this is dangerous
elsif config.allow_concurrency == :unsafe
# Do nothing, even if we know this is dangerous. This is the
# historical behaviour for true.
else
# Default concurrency setting
# Default concurrency setting: enabled, but safe
if config.cache_classes && config.eager_load
# No lock required
elsif config.cache_classes
# The load interlock is required, but not a full request
# lock
unless config.cache_classes && config.eager_load
# Without cache_classes + eager_load, the load interlock
# is required for proper operation
middleware.use ::ActionDispatch::LoadInterlock
else
# If we're reloading on each request, they all need to be
# run in isolation
middleware.use ::Rack::Lock
end
end

View file

@ -86,8 +86,10 @@ module Rails
# added in the hook are taken into account.
initializer :set_clear_dependencies_hook, group: :all do
callback = lambda do
ActiveSupport::DescendantsTracker.clear
ActiveSupport::Dependencies.clear
ActiveSupport::Dependencies.interlock.attempt_loading do
ActiveSupport::DescendantsTracker.clear
ActiveSupport::Dependencies.clear
end
end
if config.reload_classes_only_on_change

View file

@ -26,7 +26,7 @@ module ApplicationTests
assert_equal [
"Rack::Sendfile",
"ActionDispatch::Static",
"Rack::Lock",
"ActionDispatch::LoadInterlock",
"ActiveSupport::Cache::Strategy::LocalCache",
"Rack::Runtime",
"Rack::MethodOverride",
@ -58,7 +58,7 @@ module ApplicationTests
assert_equal [
"Rack::Sendfile",
"ActionDispatch::Static",
"Rack::Lock",
"ActionDispatch::LoadInterlock",
"ActiveSupport::Cache::Strategy::LocalCache",
"Rack::Runtime",
"ActionDispatch::RequestId",
@ -128,11 +128,11 @@ module ApplicationTests
assert_includes middleware, "ActionDispatch::LoadInterlock"
end
test "includes lock if cache_classes is off" do
test "includes interlock if cache_classes is off" do
add_to_config "config.cache_classes = false"
boot!
assert_includes middleware, "Rack::Lock"
assert_not_includes middleware, "ActionDispatch::LoadInterlock"
assert_not_includes middleware, "Rack::Lock"
assert_includes middleware, "ActionDispatch::LoadInterlock"
end
test "does not include lock if cache_classes is set and so is eager_load" do
@ -143,8 +143,8 @@ module ApplicationTests
assert_not_includes middleware, "ActionDispatch::LoadInterlock"
end
test "does not include lock if allow_concurrency is set" do
add_to_config "config.allow_concurrency = true"
test "does not include lock if allow_concurrency is set to :unsafe" do
add_to_config "config.allow_concurrency = :unsafe"
boot!
assert_not_includes middleware, "Rack::Lock"
assert_not_includes middleware, "ActionDispatch::LoadInterlock"