diff options
author | eileencodes <eileencodes@gmail.com> | 2015-09-29 14:10:05 -0400 |
---|---|---|
committer | eileencodes <eileencodes@gmail.com> | 2015-09-29 14:10:05 -0400 |
commit | 3a512162beb0fc46ccbb5f41505e4295a122df62 (patch) | |
tree | 95432dfad0b932ef2e9e889fac09d192d9873fc6 /railties/lib | |
parent | d951558f78cd09074abae4a49e57603b7424ad70 (diff) | |
download | rails-3a512162beb0fc46ccbb5f41505e4295a122df62.tar.gz rails-3a512162beb0fc46ccbb5f41505e4295a122df62.tar.bz2 rails-3a512162beb0fc46ccbb5f41505e4295a122df62.zip |
Make app building threadsafe
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/engine.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 2d5ff4eda9..5fe96f58ab 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -2,6 +2,7 @@ require 'rails/railtie' require 'rails/engine/railties' require 'active_support/core_ext/module/delegation' require 'pathname' +require 'thread' module Rails # <tt>Rails::Engine</tt> allows you to wrap a specific Rails application or subset of @@ -434,6 +435,7 @@ module Rails @env_config = nil @helpers = nil @routes = nil + @app_build_lock = Mutex.new super end @@ -504,10 +506,12 @@ module Rails # Returns the underlying rack application for this engine. def app - @app ||= begin - config.middleware = config.app_middleware.merge_into(config.middleware).merge_into(default_middleware_stack) - config.middleware.build(endpoint) - end + @app || @app_build_lock.synchronize { + @app ||= begin + config.middleware = config.app_middleware.merge_into(config.middleware).merge_into(default_middleware_stack) + config.middleware.build(endpoint) + end + } end # Returns the endpoint for this engine. If none is registered, |