-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Prune bundler causes rack to be loaded twice #859
Comments
My colleague pointed out that it may not be clear that the second While I could remove the |
Here's a very hacky workaround (in my if defined?(Bundler)
prune_bundler
else
require 'bundler'
$LOAD_PATH.unshift File.join(Bundler.rubygems.find_name('rack').first.full_gem_path, 'lib')
end |
We cannot fully remove the dependency on Rack because gems such as Sinatra monkey-patch their own extensions onto Rack (see puma#735). In those cases we must use the real `Rack::Builder` instead of our own `Puma::Rack::Builder`. We cannot determine the Rack path ahead of time and pass it to `puma-wild` from the `#prune_bundler` method because it would prevent Rack refreshing on restart. Instead of shelling out to `bundle show` we could consider loading Bundler and using it to determine the gem path, this would either require loading 'bundler/setup' which is undesirable as it would modify the `$LOAD_PATH` in unexpected ways, or manually implementing just enough of `Bundler.setup` ourselves, which would deeply couple Puma to the internals of Bundler.
Thanks so much for the repo but it doesn't seem to cause the issue for me! Could you list the exact shell commands you run after cloning that repo to cause the issue? |
@evanphx If you run |
Nope, it's not. Should I need to run any |
Oh, I see that the vendor dir requires me to be running ruby 2.1.0. Let me install that and try again. |
Doh! Sorry! |
Ok, so I had to run |
What version of bundler are you testing this with? Perhaps thats the variable that is keeping it from happening to me (which also means, if you could, update to the latest bundler and see if it still happens for you). |
Ok! Got it! It's not that rack is installed into a different GEM_HOME, it's that it's installed into the ruby's default gem directory (i.e. |
Thanks so much @evanphx, sorry about the misinformation! |
@evanphx thanks for merging and the speedy release! ❤️ |
Howdy! 👋
I've been converting an app to use
prune_bundler
as recommended in DEPLOYMENT.md to ensure bundled gems are properly reloaded when restarting the server withUSR1
.I noticed a lot of warnings in my logs caused by rack constants being redefined, for example:
After doing some investigation, it appears that rack is being loaded twice; once from my system-wide gems, and once from my app's
vendor
folder managed by bundler.Because
prune_bundler
removes bundled gems from the$LOAD_PATH
, it seems that this block (in configuration.rb) is loading the system-wide rack instead of the bundler rack:Which makes sense... my understanding of this method is that it assumes that if
require 'rack'
succeeds it must be running under bundler, otherwise it uses Puma's own implementation ofRack::Builder
.However in my case as the gem is installed system-wide, the
require
will succeed when not under bundler.While the obvious solution may be to simply remove the system-wide rack, I'm not sure that's the best solution because:
Reproduction Steps
I've created a simple rack app that exhibits the behaviour:
https://github.com/boxofrad/puma-double-rack
Here are the conditions under which the behaviour can be observed:
GEM_HOME
GEM_HOME
(e.g. when installing with--deployment
or--path mypath
)prune_bundler
Thanks for all of your hard work on Puma! 💖
The text was updated successfully, but these errors were encountered: