Skip to content

Fix #40518 by avoiding setting APP_PATH if already defined#40521

Closed
santib wants to merge 1 commit intorails:masterfrom
santib:fix-40518
Closed

Fix #40518 by avoiding setting APP_PATH if already defined#40521
santib wants to merge 1 commit intorails:masterfrom
santib:fix-40518

Conversation

@santib
Copy link
Contributor

@santib santib commented Nov 3, 2020

Summary

Resolves #40518

I was able to confirm that this is caused by spring. The bin/rails binstub is getting called twice when using spring, and the second time it is called, the already initialized constant warning is triggered.

image

Without spring
image

@rails-bot rails-bot bot added the railties label Nov 3, 2020
@jonathanhefner
Copy link
Member

This happens because we now load Spring after we set APP_PATH.

Prior to #39225, bundle exec spring binstub --all would inject code at the top of bin/rails to load Spring before setting APP_PATH. When bin/rails was executed, Spring would hijack the control flow, which ensured APP_PATH was set only once.

I think it would be reasonable to instead set APP_PATH in config/boot.rb, below the code that loads Spring. That should prevent setting APP_PATH twice, just as before. I would have to look into how that affects engines and plugins though, since they also have some APP_PATH-related code.

@rafaelfranca
Copy link
Member

To be fair I'm more inclined to revert the spring changes. I don't think they simplify anything in our setup, maybe the requirement of generating the binstubs, but we can still simplify generating the binstubs without changing how and when spring is loaded.

@rafaelfranca rafaelfranca added this to the 6.1.0 milestone Nov 3, 2020
@jonathanhefner
Copy link
Member

I think the original intent of the Spring changes was to ensure that, if Spring is installed, the app is always loaded via Spring in development and test, and never loaded via Spring otherwise. (Perhaps DHH can confirm?) Loading Spring in config/boot.rb ensures that all commands do that, even if bundle exec spring binstub --all has not been run, and even for commands which bundle exec spring binstub --all does not apply to (i.e. custom bins).

@rafaelfranca
Copy link
Member

rafaelfranca commented Nov 3, 2020

Loading Spring in config/boot.rb ensures that all commands do that, even if bundle exec spring binstub --all has not been run, and even for commands which bundle exec spring binstub --all does not apply to (i.e. custom bins).

All boot.rb is doing right now is checking RAILS_ENV and we can do that in bin/rails. We can generate a bin/rails with all that code already and not call, or require to call, bundle exec spring binstub --all. But, if all we want is to not sprign in development and test this code should be in spring and not in Rails.

Custom bins don't work with the current setup anyway. Spring only works for the commands that are registered on it.

jonathanhefner added a commit to jonathanhefner/rails that referenced this pull request Nov 3, 2020
Follow-up to rails#39746.

This shifts the responsibility of loading Spring from `config/boot.rb`
back to the relevant bin files.

Fixes rails#40518.
Closes rails#40521.
jonathanhefner added a commit to jonathanhefner/rails that referenced this pull request Dec 2, 2020
Follow-up to rails#39746.

This shifts the responsibility of loading Spring from `config/boot.rb`
back to the relevant bin files.

Fixes rails#40518.
Closes rails#40521.

(cherry picked from commit acc837e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

warning: already initialized constant APP_PATH

3 participants