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

Intermittent UnrecognizedScopeTarget under JRuby #75

Closed
alaz opened this issue Jun 19, 2019 · 3 comments
Closed

Intermittent UnrecognizedScopeTarget under JRuby #75

alaz opened this issue Jun 19, 2019 · 3 comments
Labels
bug Something isn't working

Comments

@alaz
Copy link

alaz commented Jun 19, 2019

Environment

Ruby Version: JRuby 9.2.7
Framework Version (Rails, whatever): Rails 5.2.3
Action Policy Version: 0.3.1

What did you do?

I am observing ActionPolicy::UnrecognizedScopeTarget occasionally upon the application's start. It happens for different models. A typical stacktrace is

vendor/bundle/jruby/2.5.0/gems/action_policy-0.3.1/lib/action_policy/policy/scoping.rb:105:in `resolve_scope_type': Couldn't infer scope type for Topic::ActiveRecord_Relation instance (ActionPolicy::UnrecognizedScopeTarget)
    from vendor/bundle/jruby/2.5.0/gems/action_policy-0.3.1/lib/action_policy/behaviours/scoping.rb:28:in `authorization_scope_type_for'
    from vendor/bundle/jruby/2.5.0/gems/action_policy-0.3.1/lib/action_policy/behaviours/scoping.rb:17:in `authorized_scope'
    from app/controllers/topics_suggest_controller.rb:44:in `topic_load'

Where topic_load is

  def topic_load
    @topic = authorized_scope(Topic.all).find params[:id]
    authorize! @topic
  end

This never happens during tests or development, being it MRI or JRuby. The application production always runs under JRuby.

Experiments

Since JRuby has fair threads, I thought it could be caused by some lack of thread safety. I have seen a similar problem before rails/rails#23699 (comment) , and I already have a special Rails route to pre-warm the application after start up. So I have simply put the following into that controller action:

    # warm up Action Policy scopes
    authorized_scope(Post.all)

The errors are gone. This makes me think that a problem with tread-safety in resolving scopes is very likely.

Regards,
Alexander

@palkan palkan added the bug Something isn't working label Jun 20, 2019
@palkan palkan closed this as completed in 0d95374 Jun 20, 2019
@palkan palkan reopened this Jun 20, 2019
@palkan
Copy link
Owner

palkan commented Jun 20, 2019

Thanks for the report!

Could you please try the version from master? I found a couple of thread-safety problems in scoping code, should be fixed now.

@alaz
Copy link
Author

alaz commented Jun 22, 2019

As far as I can see, it is fixed. I re-deployed few times at 3 servers and the problem has not shown up.

Thank you for the quick fix!

@palkan
Copy link
Owner

palkan commented Jun 27, 2019

Released in 0.3.2.

@palkan palkan closed this as completed Jun 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants