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

Make ActionController::Caching::Sweeper class thread safe #72

Merged
merged 4 commits into from
Jun 29, 2018
Merged

Make ActionController::Caching::Sweeper class thread safe #72

merged 4 commits into from
Jun 29, 2018

Conversation

Angelmmiguel
Copy link
Contributor

@Angelmmiguel Angelmmiguel commented May 30, 2018

The current implementation of ActionController::Caching::Sweeper is not Thread safe and it may cause issues in multi-thread environments. The problem is that @controller variable is lost in the different Threads. For sweepers with big loops, it might cause the following error:

undefined method `expire_action' for #<ReleaseSweeper:0x000000073b69b8 @_routes=nil, @controller=nil>

Changes

  • Store the controller variable in a current Thread property
  • Fix a deprecation message with minitest

This closes #71

@Angelmmiguel
Copy link
Contributor Author

@rafaelfranca I'm a bit afraid of the compatibility of this PR with the current usage of the gem. I see some people suggesting to use @controller ||= ActionController::Base.new to avoid @controller to be nil. However, with these changes, the code will be different:

self.controller ||= ActionController::Base.new

@Angelmmiguel
Copy link
Contributor Author

Angelmmiguel commented Jun 12, 2018

@rafaelfranca Should I perform any other change? :)

Copy link
Member

@rafaelfranca rafaelfranca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine. If people want to avoid nil they can use the writer.

controller.__send__(method, *arguments, &block)
end

# @see https://robots.thoughtbot.com/always-define-respond-to-missing-when-overriding
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove this comment

@Angelmmiguel
Copy link
Contributor Author

Done @rafaelfranca !

@rafaelfranca rafaelfranca merged commit 3a7a627 into rails:master Jun 29, 2018
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

Successfully merging this pull request may close these issues.

ActionController::Caching::Sweeper controller instance is not thread safe
2 participants