Rails console fails because application needs to have reloading enabled (config.cache_classes)

I hit the following error in a Rails 7 prod instance while trying to use the console command:

console_command = "rails console"

The error I got:

Connecting to xxxxxxxxxxxx... complete
[07/10/23 09:16:53 +0000 xxxxxx (242)] INFO : No configuration file loaded, and no configuration found in ENV. For assistance configuring Scout, visit https://docs.scoutapm.com/#ruby-configuration-options
[07/10/23 09:16:53 +0000 xxxxxx (242)] INFO : Scout Agent [5.2.0] Initialized
[07/10/23 09:16:53 +0000 xxxxxx (242)] INFO : Not Loading Instruments
[07/10/23 09:16:53 +0000 xxxxxx (242)] INFO : Scout Agent [5.2.0] Installed
[07/10/23 09:16:53 +0000 xxxxxx (242)] INFO : Monitoring isn't enabled for the [production] environment.
[07/10/23 09:16:53 +0000 xxxxxx (242)] INFO : Deferring agent start. Standing by for first request
/usr/local/bundle/gems/spring-4.0.0/lib/spring/application.rb:101:in `block in preload': Spring reloads, and therefore needs the application to have reloading enabled.
Please, set config.cache_classes to false in config/environments/production.rb.
 (RuntimeError)
        from /usr/local/bundle/gems/railties-7.0.3.1/lib/rails/initializable.rb:32:in `instance_exec'
        from /usr/local/bundle/gems/railties-7.0.3.1/lib/rails/initializable.rb:32:in `run'
        from /usr/local/bundle/gems/railties-7.0.3.1/lib/rails/initializable.rb:61:in `block in run_initializers'
        from /usr/local/lib/ruby/3.1.0/tsort.rb:228:in `block in tsort_each'
        from /usr/local/lib/ruby/3.1.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
        from /usr/local/lib/ruby/3.1.0/tsort.rb:431:in `each_strongly_connected_component_from'
        from /usr/local/lib/ruby/3.1.0/tsort.rb:349:in `block in each_strongly_connected_component'
        from /usr/local/lib/ruby/3.1.0/tsort.rb:347:in `each'
        from /usr/local/lib/ruby/3.1.0/tsort.rb:347:in `call'
        from /usr/local/lib/ruby/3.1.0/tsort.rb:347:in `each_strongly_connected_component'
        from /usr/local/lib/ruby/3.1.0/tsort.rb:226:in `tsort_each'
        from /usr/local/lib/ruby/3.1.0/tsort.rb:205:in `tsort_each'
        from /usr/local/bundle/gems/railties-7.0.3.1/lib/rails/initializable.rb:60:in `run_initializers'
        from /usr/local/bundle/gems/railties-7.0.3.1/lib/rails/application.rb:372:in `initialize!'
        from /app/config/environment.rb:5:in `<main>'
        from /usr/local/bundle/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        from /usr/local/bundle/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        from /usr/local/bundle/gems/zeitwerk-2.6.0/lib/zeitwerk/kernel.rb:35:in `require'
        from /usr/local/bundle/gems/spring-4.0.0/lib/spring/application.rb:108:in `preload'
        from /usr/local/bundle/gems/spring-4.0.0/lib/spring/application.rb:162:in `serve'
        from /usr/local/bundle/gems/spring-4.0.0/lib/spring/application.rb:144:in `block in run'
        from /usr/local/bundle/gems/spring-4.0.0/lib/spring/application.rb:138:in `loop'
        from /usr/local/bundle/gems/spring-4.0.0/lib/spring/application.rb:138:in `run'
        from /usr/local/bundle/gems/spring-4.0.0/lib/spring/application/boot.rb:19:in `<top (required)>'
        from <internal:/usr/local/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:/usr/local/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from -e:1:in `<main>'

I’ve never seen that message before.

Can I ask what you are using spring for? Spring is only intended for development, and was dropped in Rails 7. I haven’t taken a look at what it would take to support Spring in production on Rails 7, but I would recommend dropping Spring entirely; or - if you need it in development - only including and configuring it in development.

so our Rails app started at 5 and we’ve upgraded it through time. My guess is it’s one of those things that came default and we’re not really aware of or really use it. That said we haven’t seen this issue in our Heroku environment (we’re in the process of migrating).

I think the correct thing to do is probably disable spring boot for other environments, but I was able to workaround the issue by simply changing our console command in the toml file to:

console_command = "env DISABLE_SPRING=true rails console"

Thanks for the quick response though!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.