Commit fdfc8d04 authored by Jan Provaznik's avatar Jan Provaznik

[Rails5] Permit concurrent loads

Rails 5 introduced a new (and safer) autoload mechanism which
uses locking when loading missing constants. Under some circumstances
it's possible that a deadlock occurs in multi-threaded environment
(especially when running capybara tests)

To avoid these deadlocks, concurrent load is enabled when loading
policies - we ere hitting timeout in this case:
https://gitlab.com/gitlab-org/gitlab-ce/issues/48263

Note that autoloading is enabled only in development or test envs
(not in production).
parent f3edbafe
......@@ -21,7 +21,17 @@ module DeclarativePolicy
cache = opts[:cache] || {}
key = Cache.policy_key(user, subject)
cache[key] ||= class_for(subject).new(user, subject, opts)
cache[key] ||=
if Gitlab.rails5?
# to avoid deadlocks in multi-threaded environment when
# autoloading is enabled, we allow concurrent loads,
# https://gitlab.com/gitlab-org/gitlab-ce/issues/48263
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
class_for(subject).new(user, subject, opts)
end
else
class_for(subject).new(user, subject, opts)
end
end
def class_for(subject)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment