Skip to content

Avoid use of bundler/setup during rails booting #459

Description

@chadlwilson

Currently jruby-rack tries to boot rails in the standish-way that can swallow any bundler errors if Java is not configured with particular --add-opens etc (depending on platform). it does this via:

def load_environment
require expand_path('config/boot.rb')
require 'jruby/rack/rails/railtie'
require expand_path('config/environment.rb')
require 'jruby/rack/rails/extensions'
end

The issue is that an off-the-shelf Rails config/boot.rb will do require bundler/setup to Boot rails. This is problematic because in order to determine which mode to run in, Bundler does an stdout.tty? check.

https://github.com/ruby/rubygems/blob/b3f354a72845e5614190a19eb78d76f9ca91cc32/lib/bundler/setup.rb#L14

Unfortunately this particular check is problematic on JRuby because it requires all manner of native access to do correctly, and versions prior to 10.0.7.0 will silently return true if these are not available, due to jruby/jruby#9590 This then causes bundler to do things like System.exit any time there is an error, which will be caught by the servlet container and otherwise swallow any actual Bundling error.

It also does problematic things like trying to auto_switch to locked bundler versions and auto_install gems, which should not be done within jruby-rack. The former has been a problem for some time, requiring workarounds such as locking to the same jruby-bundled bundler version, or using BUNDLE_VERSION=system and/or BUNDLE_DISABLE_SHARED_GEMS=1 when building ones application; neither of which should be required at build time.

All of this is probably unnecessary.

  • jruby-rack can always assume there is no tty
  • theoretically we can call Bundler.setup programmatically prior to the user's boot and short-circuit all of this
    • this assumes bundler is in use. I believe this is fine, as think using Bundler is required for rails?
    • unfortunately we would not know any custom Bundler.setup the user is doing in their config.boot.rb.
      • we may need to parse/grep config/boot.rb and only do our own Bundler.setup if there is none there; or if we see require bundler/setup.
  • after that, the user's require 'bundler/setup' should be largely a no-op; or at least the tty status will be irrelevant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    rubyPull requests that update Ruby code

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions