Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace MutexHook by MonitorHook to allow reentrancy #45857

Merged
merged 1 commit into from Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions railties/CHANGELOG.md
@@ -1,3 +1,10 @@
* `config.allow_concurrency = false` now use a `Monitor` instead of a `Mutex`

This allows to enable `config.active_support.executor_around_test_case` even
when `config.allow_concurrency` is disabled.

*Jean Boussier*

* Add `routes --unused` option to detect extraneous routes.

Example:
Expand Down
14 changes: 7 additions & 7 deletions railties/lib/rails/application/finisher.rb
Expand Up @@ -87,21 +87,21 @@ module Finisher
ActiveSupport.run_load_hooks(:after_initialize, self)
end

class MutexHook
def initialize(mutex = Mutex.new)
@mutex = mutex
class MonitorHook # :nodoc:
def initialize(monitor = Monitor.new)
@monitor = monitor
end

def run
@mutex.lock
@monitor.enter
end

def complete(_state)
@mutex.unlock
@monitor.exit
end
end

module InterlockHook
module InterlockHook # :nodoc:
def self.run
ActiveSupport::Dependencies.interlock.start_running
end
Expand All @@ -116,7 +116,7 @@ def self.complete(_state)
# User has explicitly opted out of concurrent request
# handling: presumably their code is not threadsafe

app.executor.register_hook(MutexHook.new, outer: true)
app.executor.register_hook(MonitorHook.new, outer: true)

elsif config.allow_concurrency == :unsafe
# Do nothing, even if we know this is dangerous. This is the
Expand Down