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

How to permit concurrent loads in Rails 4.2? #37675

Closed
vaibhavatul47 opened this issue Nov 10, 2019 · 1 comment
Closed

How to permit concurrent loads in Rails 4.2? #37675

vaibhavatul47 opened this issue Nov 10, 2019 · 1 comment

Comments

@vaibhavatul47
Copy link

Steps to reproduce

When writing a multithreaded application it is advised to enable concurrent loads to avoid deadlock during autoloading.

ActiveSupport::Dependencies.interlock.permit_concurrent_loads

link to guide

The example in the guide is for Rails 5, how can I achieve this in Rails 4.2? I couldn't find interlock.rb file inside active_support/dependencies directory.

Expected behavior

  futures = @current_user.posts.map do |p|
      Concurrent::Promises.future(p) do |post|
        ActiveRecord::Base.connection_pool.with_connection do
          post.cleanup_comments # Calls an API which takes ~2minutes
          post.destroy
        end
      end
    end

    responses = futures.map(&:value)

This code should be able to destroy all posts of current-user concurrently.

Actual behavior

When I execute this code I get: Circular dependency detected while autoloading constant error

Note: I was able to solve this problem by putting these two lines in my config/application.rb file, but I'm not sure if thats the correct way to solve this circular dependency deadlock issue.

config.cache_classes = true
config.eager_load = true

System configuration

Rails version: rails -v # Rails 4.2.8

Ruby version: ruby -v # ruby 2.3.4p301 (2017-03-30 revision 58214) [x86_64-darwin18]

@vaibhavatul47 vaibhavatul47 changed the title How to permit concurrent loads in Rails 4? How to permit concurrent loads in Rails 4.2? Nov 10, 2019
@kaspth
Copy link
Contributor

kaspth commented Nov 10, 2019

You can’t because it was added for Rails 5.0 iirc. Rails 4.2 is unsupported now, so the only to be able to enable that is to upgrade your Rails app. Thanks!

@kaspth kaspth closed this as completed Nov 10, 2019
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