-
Notifications
You must be signed in to change notification settings - Fork 341
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
Need a way to restart server on important environment variable changes #420
Comments
are there env vars that change and should not trigger a reload ? |
I don't know. I originally thought it should reload on any ENV change, but wasn't sure what kind of unintended consequences that might have. The full reload is pretty drastic (kills all spring perf benefits), so I figured we should be conservative with it and only use it for values we know we care about. But I think not-respecting environment variable changes is a major violation of "principle of least astonishment" and people will collectively continue to lose hours of productivity until it is addressed. |
@jonleighton @rafaelfranca thoughts on this env whitelisting vs blacklisting <-> restart ? |
I don't know of any usecase that has a constantly changing environment, so I'd prefer restart on every change and wait for someone to complain ... log message should be nice and clear like "ENV XYZ change detected, restarting" |
I think we can try that. |
@joshuaflanagan PR time ? :) |
I'm going to need more guidance to get to a PR. I spent some time trying to solve the problem this morning, got that failing test, and wrote the naive code that makes it pass, but couldn't figure out how to compare the old/new ENV values at that point in the code ( I'd be happy to work on a PR, but need a nudge on the best way to get access to the old and new values at that point. Or if there is a better place to do the comparison and still trigger a reload. For example, it is very easy to detect if the ENV has changed here spring/lib/spring/application.rb Line 145 in 770b2b1
|
On my machine,
I have no idea what Some more guaranteed changes:
|
@matthewd makes a good point... Could we perhaps detect which |
I don't see how we could, without doing some voodoo like monkeypatching |
are you suggesting something like adding |
That is exactly what I had in mind. |
Still biting me a year later. |
Same. I remove spring from my applications for this reason. Is there any way to force spring to fully reload? If I can do it manually, I will not continue to remove it. |
how to run a watchdog? I'm tired to run |
If you just want to watch changes in files, and assuming your system supports fswatch:
You can replace This doesn't help with environment variables, it just watches files. A hack for environment variables would be to do something like:
and then add |
What if we tackled a smaller problem that doesn't try to solve how to track ENV vars consistently. Here's a typical Spring config: # config/spring.rb
Spring.watch(
'tmp/restart.txt',
'tmp/caching-dev.txt',
'config/application.yml' # env vars stored here (Figaro gem)
) Updating the mtime to any of those files triggers a restart which is ideal for 2 of the 3 files 👍 Its the 3rd file, How about if something like this was possible? # config/spring.rb
Spring.watch(
restart: ['tmp/restart.txt', 'tmp/caching-dev.txt'], # forces a restart
stop: 'config/application.yml' # forces spring stop
) The method call doesn't have to be keyword arg based, it could be a new method like Would a contribution adding something along these lines to Spring be welcome? If yes, what API would you like? |
My previous comment was pretty wrong - I'm sorry, it was based on me not digging deep enough into an environment variable error I was seeing in my local env - it turns out that for |
+1, important to make |
Would the spring maintainers be open to adding a method to register env vars for comparison between the server and the invoking client and doing a restart if they change? Letting developers whitelist env vars for restarts seems like a good, non-invasive option to me! |
Been trying to figure out why Spring works initially and has all my ENV variables, but then later seems to not have any, and I think this issue is related somehow. Spring seems to be losing my env, but only sometimes.
I am setting SolvedI had two spring processes running, and only one of them was being restarted manually by me. https://www.jetbrains.com/help/ruby/spring.html#stop_spring It would be amazing if the "hidden" spring process in the IDE could reload when the ENV changed! |
A lot of people have been bitten by the fact that spring doesn't reload application config (database.yml, config/initializers) with new environment variables.
DATABASE_URL
is a perfect example. There is a PR that attempts to solve part of the problem (#267), but even the comments there indicate there is still room for confusing behavior.We need a way to specify a set of environment variables that should trigger a full reload. By default, it may just include
DATABASE_URL
, but you should be able to add your own environment variables to that list, in case you use them in initializers.I tried diving into the code to create a PR, but don't have a strong enough understanding of the different environments in play. I wrote a failing test that demonstrates the problem.
As an example, I can get this to pass by making the following change:
Obviously, that isn't what we want, since it reboots the server every time. But if we could detect the ENV change at that point, we could conditionally restart everything.
The text was updated successfully, but these errors were encountered: