diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-07-10 15:42:08 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-07-10 15:42:08 -0700 |
commit | 8f81f7a73d4a5433fe8af57f706d4d1e37d8459b (patch) | |
tree | 6a521f59a2bd976ce6c5974e77e8f30f9df768fc /railties/lib/rails | |
parent | 17a6e603bbc64157f0fc0b648ae1a4f1db97ca7d (diff) | |
parent | 0b93c48bbe74857ead9a9ef56b35f87965edbb49 (diff) | |
download | rails-8f81f7a73d4a5433fe8af57f706d4d1e37d8459b.tar.gz rails-8f81f7a73d4a5433fe8af57f706d4d1e37d8459b.tar.bz2 rails-8f81f7a73d4a5433fe8af57f706d4d1e37d8459b.zip |
Merge pull request #17102 from matthewd/load-interlock
Concurrent load interlock (rm Rack::Lock)
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/application/default_middleware_stack.rb | 30 | ||||
-rw-r--r-- | railties/lib/rails/application/finisher.rb | 6 |
2 files changed, 25 insertions, 11 deletions
diff --git a/railties/lib/rails/application/default_middleware_stack.rb b/railties/lib/rails/application/default_middleware_stack.rb index 6f9ccec137..88eade5c5a 100644 --- a/railties/lib/rails/application/default_middleware_stack.rb +++ b/railties/lib/rails/application/default_middleware_stack.rb @@ -26,7 +26,27 @@ module Rails middleware.use ::Rack::Cache, rack_cache end - middleware.use ::Rack::Lock unless allow_concurrency? + if config.allow_concurrency == false + # User has explicitly opted out of concurrent request + # handling: presumably their code is not threadsafe + + middleware.use ::Rack::Lock + + 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: enabled, but safe + + unless config.cache_classes && config.eager_load + # Without cache_classes + eager_load, the load interlock + # is required for proper operation + + middleware.use ::ActionDispatch::LoadInterlock + end + end + middleware.use ::Rack::Runtime middleware.use ::Rack::MethodOverride unless config.api_only middleware.use ::ActionDispatch::RequestId @@ -65,14 +85,6 @@ module Rails config.reload_classes_only_on_change != true || app.reloaders.map(&:updated?).any? end - def allow_concurrency? - if config.allow_concurrency.nil? - config.cache_classes && config.eager_load - else - config.allow_concurrency - end - end - def load_rack_cache rack_cache = config.action_dispatch.rack_cache return unless rack_cache diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 0599e988d9..f8f92792a7 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -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 |