Preserve BUNDLE_APP_CONFIG on worker fork (#2688)

Without this, if puma is launched with BUNDLE_APP_CONFIG set, that will
be lost inside of unbundled_env, which causes the worker processes to use a
potentially different bundler configuration.
This commit is contained in:
Jonathan del Strother 2021-09-03 18:52:35 +01:00 committed by GitHub
parent 35194c575b
commit 3c5d12db6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 0 deletions

View File

@ -319,10 +319,12 @@ module Puma
log '* Pruning Bundler environment'
home = ENV['GEM_HOME']
bundle_gemfile = Bundler.original_env['BUNDLE_GEMFILE']
bundle_app_config = Bundler.original_env['BUNDLE_APP_CONFIG']
with_unbundled_env do
ENV['GEM_HOME'] = home
ENV['BUNDLE_GEMFILE'] = bundle_gemfile
ENV['PUMA_BUNDLER_PRUNED'] = '1'
ENV["BUNDLE_APP_CONFIG"] = bundle_app_config
args = [Gem.ruby, puma_wild_location, '-I', dirs.join(':')] + @original_argv
# Ruby 2.0+ defaults to true which breaks socket activation
args += [{:close_others => false}]

View File

@ -0,0 +1,2 @@
---
BUNDLE_PATH: "vendor/bundle"

View File

@ -0,0 +1 @@
gem 'puma', path: '../..'

View File

@ -0,0 +1 @@
run lambda { |env| [200, {"Content-Type" => "text/plain"}, ["Hello World"]] }

View File

@ -39,6 +39,27 @@ class TestPreserveBundlerEnv < TestIntegration
assert_match("Gemfile.bundle_env_preservation_test", new_reply)
end
def test_worker_forking_preserves_bundler_config_path
skip_unless_signal_exist? :TERM
@tcp_port = UniquePort.call
env = {
# Disable the .bundle/config file in the bundle_app_config_test directory
"BUNDLE_APP_CONFIG" => "/dev/null",
# Don't allow our (rake test's) original env to interfere with the child process
"BUNDLE_GEMFILE" => nil,
"BUNDLER_ORIG_BUNDLE_GEMFILE" => nil
}
cmd = "bundle exec puma -q -w 1 --prune-bundler -b tcp://#{HOST}:#{@tcp_port}"
Dir.chdir File.expand_path("bundle_app_config_test", __dir__) do
@server = IO.popen(env, cmd.split, "r")
end
wait_for_server_to_boot
@pid = @server.pid
reply = read_body(connect)
assert_equal("Hello World", reply)
end
def test_phased_restart_preserves_unspecified_bundle_gemfile
skip_unless_signal_exist? :USR1