Skip to content

Commit

Permalink
Preserve BUNDLE_APP_CONFIG on worker fork
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jdelStrother committed Sep 3, 2021
1 parent be20fac commit a8ea7e3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/puma/launcher.rb
Expand Up @@ -319,10 +319,12 @@ def prune_bundler
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}]
Expand Down
2 changes: 2 additions & 0 deletions test/bundle_app_config_test/.bundle/config
@@ -0,0 +1,2 @@
---
BUNDLE_PATH: "vendor/bundle"
1 change: 1 addition & 0 deletions test/bundle_app_config_test/Gemfile
@@ -0,0 +1 @@
gem 'puma', path: '../..'
1 change: 1 addition & 0 deletions test/bundle_app_config_test/config.ru
@@ -0,0 +1 @@
run lambda { |env| [200, {"Content-Type" => "text/plain"}, ["Hello World"]] }
21 changes: 21 additions & 0 deletions test/test_preserve_bundler_env.rb
Expand Up @@ -39,6 +39,27 @@ def test_usr2_restart_preserves_bundler_environment
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

Expand Down

0 comments on commit a8ea7e3

Please sign in to comment.