Skip to content
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

Preserve BUNDLE_APP_CONFIG on worker fork #2688

Merged
merged 1 commit into from Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locally, if I undo the change introduced to prune_bundler,

git restore --source HEAD^ -- lib

This test is still green. In other words, the test does not appear to guard against a regression for the new functionality.

Do you think it is possible to write this test in a way that it fails on master in the way you observed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bah, I was testing with ruby -Ilib:test test/test_preserve_bundler_env.rb which does fail on master, but looks like the same thing inside of bundle exec doesn't.

I've force-pushed an update that sets BUNDLE_GEMFILE in the test, which should persuade it to fail in either scenario (and then subsequently be fixed by the BUNDLE_APP_CONFIG change).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

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