Skip to content

config/spring.rb loaded after Spring.application_root_path is memoized #582

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

Open
petekinnecom opened this issue Dec 25, 2018 · 0 comments
Open

Comments

@petekinnecom
Copy link

Hi,

We have run into an issue with our usage of Spring (I believe it is the same issue that folks are running in to here: #323). In our case, we have engines inside of an application but we only use a single top-level Gemfile. This has exposed an issue with the order of events when loading of the config/spring.rb.

For us, our config/spring.rb loaded after Spring.application_root_path is memoized and so our config/spring.rb does not have the correct effect.

Here is the issue as I have been able to track it down:

Consider running the command:

bundle exec spring rails runner 'puts :ok'

Spring loads the client/ files and decides it needs to start a server. That eventually leads to spring/commands getting loaded, which loads the config/spring.rb:

config = File.expand_path("./config/spring.rb")

Spring then decides to spawn a server in the background:

@pid = Process.spawn(

This process spawns and loads this file (note it is in a new process, so it will again need to read the config/spring.rb):

https://github.com/rails/spring/blob/1f44a267a2476658af86b0bc1afb94588a36ed04/lib/spring/application/boot.rb

The app.run on line 19 will lead to the server getting loaded and leads to the spring/commands.rb getting loaded which loads the config/spring.rb See:

BUT, here is the problem, line 15:

"spring app | #{app.app_name} | started #{distance} ago | #{app.app_env} mode"

This calls app.app_name which traces all the way down to the line:

@application_root_path ||= begin

This method then hits the default behavior BEFORE Spring has loaded the config/spring.rb. This value is memoized, by the time the config/spring.rb is loaded, its changes to Spring.application_root have no effect.


So, requiring spring/commands somewhere before hitting this line solves the issue:

"spring app | #{app.app_name} | started #{distance} ago | #{app.app_env} mode"

However, based on this line, it seems that we want that to be lazily required, so I'm not sure where exactly the best place to put it would be:


For those looking for a workaround in the meantime, adding the following to config/spring.rb will fix the issue and make Spring respect your local config/spring.rb in engine dummy apps:

Spring.instance_variable_set(:@application_root_path, nil)
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

1 participant