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

using_access_control causes hangs on Rails 5.0 #28

Open
samstickland opened this issue Apr 6, 2022 · 4 comments
Open

using_access_control causes hangs on Rails 5.0 #28

samstickland opened this issue Apr 6, 2022 · 4 comments

Comments

@samstickland
Copy link

Firstly, thanks for creating this gem, it's helping us out.

We our upgrading an old application to Rails 5.0 (5.0.7.2), and have switched to your gem (1.0.0) for this.

Including this DSL entry in a model using_access_control causes our tests to hang when these models are created (via FactoryBot).

I wonder if you could suggest some code that we can start digging into debugging purposes?

@samstickland
Copy link
Author

Oh, I found the problem - an infinite loop - here:

[370, 379] in /Users/sam/.gem/ruby/2.6.9/gems/ae_declarative_authorization-1.0.0/lib/declarative_authorization/authorization.rb
   370:       raise AuthorizationUsageError, 'No context given or inferable from object' unless context
   371:       hierarchy = rev_priv_hierarchy
   372:
   373:       flattened_privileges = privileges.clone
   374:       flattened_privileges.each do |priv|
=> 375:         flattened_privileges.concat(hierarchy[[priv, nil]]) if hierarchy[[priv, nil]]
   376:         flattened_privileges.concat(hierarchy[[priv, context]]) if hierarchy[[priv, context]]
   377:       end
   378:       flattened_privileges.uniq
   379:     end
(byebug) flattened_privileges
[:create, :manage, :translate, :manage, :translate, :manage, :translate, :manage, :translate, :manage, :translate, :manage, :translate]
(byebug) privileges
[:create]
(byebug) hierarchy[[priv, nil]]
[:manage, :translate]

It loops over flatten_privileges but it's adding to flatten privileges as it goes, so the loop never finishes.

This is on Ruby 2.6.9 - perhaps the behaviour of each is different later versions of Ruby?

@samstickland
Copy link
Author

Changing the each statement to:

privileges.each do |priv|

resolves this issue for us.

@dvicory
Copy link
Collaborator

dvicory commented May 10, 2022

@samstickland While this change seems fine, just to confirm - your test suite and everything after this change is good? We don't use using_access_control internally, so we don't have a baseline to compare with.

@samstickland
Copy link
Author

Yes, this fixed the problem for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants