[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).
This commit is contained in:
parent
f3edbafe63
commit
fdfc8d04d2
1 changed files with 11 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue