{"action":"created","issue":{"url":"https://api.github.com/repos/puma/puma/issues/859","labels_url":"https://api.github.com/repos/puma/puma/issues/859/labels{/name}","comments_url":"https://api.github.com/repos/puma/puma/issues/859/comments","events_url":"https://api.github.com/repos/puma/puma/issues/859/events","html_url":"https://github.com/puma/puma/issues/859","id":126881839,"number":859,"title":"Prune bundler causes rack to be loaded twice","user":{"login":"boxofrad","id":580803,"avatar_url":"https://avatars.githubusercontent.com/u/580803?v=3","gravatar_id":"","url":"https://api.github.com/users/boxofrad","html_url":"https://github.com/boxofrad","followers_url":"https://api.github.com/users/boxofrad/followers","following_url":"https://api.github.com/users/boxofrad/following{/other_user}","gists_url":"https://api.github.com/users/boxofrad/gists{/gist_id}","starred_url":"https://api.github.com/users/boxofrad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/boxofrad/subscriptions","organizations_url":"https://api.github.com/users/boxofrad/orgs","repos_url":"https://api.github.com/users/boxofrad/repos","events_url":"https://api.github.com/users/boxofrad/events{/privacy}","received_events_url":"https://api.github.com/users/boxofrad/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-01-15T14:22:07Z","updated_at":"2016-01-15T15:14:34Z","closed_at":null,"body":"Howdy! :wave: \r\n\r\nI've been converting an app to use `prune_bundler` as recommended in [DEPLOYMENT.md](https://github.com/puma/puma/blob/master/DEPLOYMENT.md#restarting) to ensure bundled gems are properly reloaded when restarting the server with `USR1`.\r\n\r\nI noticed a lot of warnings in my logs caused by rack constants being redefined, for example:\r\n\r\n```\r\n/home/vagrant/development/puma-double-rack/vendor/ruby/2.1.0/gems/rack-1.6.4/lib/rack.rb:14: warning: already initialized constant Rack::VERSION\r\n/var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack.rb:14: warning: previous definition of VERSION was here\r\n```\r\n\r\nAfter 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.\r\n\r\nBecause `prune_bundler` removes bundled gems from the  `$LOAD_PATH`, it seems that this block (in [configuration.rb](https://github.com/puma/puma/blob/d5914573c90fe6f8b9422f397e28c0358ce4aa3b/lib/puma/configuration.rb#L130-L140)) is loading the system-wide rack instead of the bundler rack:\r\n\r\n```ruby\r\n# Load and use the normal Rack builder if we can, otherwise\r\n# fallback to our minimal version.\r\ndef rack_builder\r\n  begin\r\n    require 'rack'\r\n    require 'rack/builder'\r\n  rescue LoadError\r\n    # ok, use builtin version\r\n    return Puma::Rack::Builder\r\n  else\r\n    return ::Rack::Builder\r\n  end\r\nend\r\n```\r\n\r\nWhich 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 of `Rack::Builder`. \r\nHowever in my case as the gem is installed system-wide, the `require` will succeed when not under bundler.\r\n\r\nWhile the obvious solution may be to simply remove the system-wide rack, I'm not sure that's the best solution because:\r\n\r\n1. In my particular case, it's not feasible to remove the system-wide rack.\r\n2. This behaviour breaks the isolation / safety contract provided by bundler, if a gem is bundled it should always be preferred over the system-wide gem.\r\n\r\n## Reproduction Steps\r\n\r\nI've created a simple rack app that exhibits the behaviour:\r\n\r\nhttps://github.com/boxofrad/puma-double-rack\r\n\r\nHere are the conditions under which the behaviour can be observed:\r\n\r\n- One copy of rack is installed in `GEM_HOME`\r\n- Another copy of rack is installed by bundler\r\n- Bundler is configured to install gems to a path other than `GEM_HOME` (e.g. when installing with `--deployment` or `--path mypath`)\r\n- Puma is configured with `prune_bundler`\r\n\r\nThanks for all of your hard work on Puma! :sparkling_heart: "},"comment":{"url":"https://api.github.com/repos/puma/puma/issues/comments/171987939","html_url":"https://github.com/puma/puma/issues/859#issuecomment-171987939","issue_url":"https://api.github.com/repos/puma/puma/issues/859","id":171987939,"user":{"login":"boxofrad","id":580803,"avatar_url":"https://avatars.githubusercontent.com/u/580803?v=3","gravatar_id":"","url":"https://api.github.com/users/boxofrad","html_url":"https://github.com/boxofrad","followers_url":"https://api.github.com/users/boxofrad/followers","following_url":"https://api.github.com/users/boxofrad/following{/other_user}","gists_url":"https://api.github.com/users/boxofrad/gists{/gist_id}","starred_url":"https://api.github.com/users/boxofrad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/boxofrad/subscriptions","organizations_url":"https://api.github.com/users/boxofrad/orgs","repos_url":"https://api.github.com/users/boxofrad/repos","events_url":"https://api.github.com/users/boxofrad/events{/privacy}","received_events_url":"https://api.github.com/users/boxofrad/received_events","type":"User","site_admin":false},"created_at":"2016-01-15T15:14:34Z","updated_at":"2016-01-15T15:14:34Z","body":"Here's a **very** hacky workaround (in my `puma.rb`) that forces the bundler version into the `$LOAD_PATH` before the system-wide version:\r\n\r\n```ruby\r\nif defined?(Bundler)\r\n  prune_bundler\r\nelse\r\n  require 'bundler'\r\n  $LOAD_PATH.unshift File.join(Bundler.rubygems.find_name('rack').first.full_gem_path, 'lib')\r\nend\r\n```"}}