Skip to content

Commit

Permalink
Return processing lock to dispatcher. This fixes class reloading race…
Browse files Browse the repository at this point in the history
… in development mode.

Without this fix class reloading is unguarded and our app easily hits this race.

This reverts commit 19db0b7 "Added back ActionController::Base.allow_concurrency flag and moved lock down to controller processing."
  • Loading branch information
Aliaksey Kandratsenka committed Oct 4, 2008
1 parent 1b552bd commit db5d9ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
15 changes: 1 addition & 14 deletions actionpack/lib/action_controller/base.rb
Expand Up @@ -284,14 +284,6 @@ class Base
@@debug_routes = true
cattr_accessor :debug_routes

# Indicates whether to allow concurrent action processing. Your
# controller actions and any other code they call must also behave well
# when called from concurrent threads. Turned off by default.
@@allow_concurrency = false
cattr_accessor :allow_concurrency

@@guard = Monitor.new

# Modern REST web services often need to submit complex data to the web application.
# The <tt>@@param_parsers</tt> hash lets you register handlers which will process the HTTP body and add parameters to the
# <tt>params</tt> hash. These handlers are invoked for POST and PUT requests.
Expand Down Expand Up @@ -532,12 +524,7 @@ def process(request, response, method = :perform_action, *arguments) #:nodoc:
assign_names

log_processing

if @@allow_concurrency
send(method, *arguments)
else
@@guard.synchronize { send(method, *arguments) }
end
send(method, *arguments)

send_response
ensure
Expand Down
18 changes: 11 additions & 7 deletions actionpack/lib/action_controller/dispatcher.rb
Expand Up @@ -2,6 +2,8 @@ module ActionController
# Dispatches requests to the appropriate controller and takes care of
# reloading the app after each request when Dependencies.load? is true.
class Dispatcher
@@guard = Mutex.new

class << self
def define_dispatcher_callbacks(cache_classes)
unless cache_classes
Expand Down Expand Up @@ -99,13 +101,15 @@ def initialize(output = $stdout, request = nil, response = nil)
end

def dispatch
begin
run_callbacks :before_dispatch
handle_request
rescue Exception => exception
failsafe_rescue exception
ensure
run_callbacks :after_dispatch, :enumerator => :reverse_each
@@guard.synchronize do
begin
run_callbacks :before_dispatch
handle_request
rescue Exception => exception
failsafe_rescue exception
ensure
run_callbacks :after_dispatch, :enumerator => :reverse_each
end
end
end

Expand Down

0 comments on commit db5d9ae

Please sign in to comment.