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

Leave BUNDLE_GEMFILE unset in workers if it was unset in the master #2154

Merged
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
3 changes: 2 additions & 1 deletion History.md
Expand Up @@ -21,8 +21,9 @@
* Preserve `BUNDLE_GEMFILE` env var when using `prune_bundler` (#1893)
* Send 408 request timeout even when queue requests is disabled (#2119)
* Rescue IO::WaitReadable instead of EAGAIN for blocking read (#2121)
* Ensure `BUNDLE_GEMFILE` is unspecified in workers if unspecified in master when using `prune_bundler` (#2154)
* Rescue and log exceptions in hooks defined by users (on_worker_boot, after_worker_fork etc) (#1551)

* Refactor
* Remove unused loader argument from Plugin initializer (#2095)
* Simplify `Configuration.random_token` and remove insecure fallback (#2102)
Expand Down
2 changes: 1 addition & 1 deletion lib/puma/launcher.rb
Expand Up @@ -300,7 +300,7 @@ def prune_bundler

log '* Pruning Bundler environment'
home = ENV['GEM_HOME']
bundle_gemfile = ENV['BUNDLE_GEMFILE']
bundle_gemfile = Bundler.original_env['BUNDLE_GEMFILE']
with_unbundled_env do
ENV['GEM_HOME'] = home
ENV['BUNDLE_GEMFILE'] = bundle_gemfile
Expand Down
1 change: 1 addition & 0 deletions test/bundle_preservation_test/version1/Gemfile
@@ -0,0 +1 @@
gem 'puma', path: '../../..'
1 change: 1 addition & 0 deletions test/bundle_preservation_test/version1/config.ru
@@ -0,0 +1 @@
run lambda { |env| [200, {'Content-Type'=>'text/plain'}, [ENV['BUNDLE_GEMFILE'].inspect]] }
1 change: 1 addition & 0 deletions test/bundle_preservation_test/version1/config/puma.rb
@@ -0,0 +1 @@
directory File.expand_path("../../current", __dir__)
1 change: 1 addition & 0 deletions test/bundle_preservation_test/version2/Gemfile
@@ -0,0 +1 @@
gem 'puma', path: '../../..'
1 change: 1 addition & 0 deletions test/bundle_preservation_test/version2/config.ru
@@ -0,0 +1 @@
run lambda { |env| [200, {'Content-Type'=>'text/plain'}, [ENV['BUNDLE_GEMFILE'].inspect]] }
1 change: 1 addition & 0 deletions test/bundle_preservation_test/version2/config/puma.rb
@@ -0,0 +1 @@
directory File.expand_path("../../current", __dir__)
54 changes: 54 additions & 0 deletions test/test_preserve_bundler_env.rb
Expand Up @@ -7,6 +7,11 @@ def setup
super
end

def teardown
FileUtils.rm current_release_symlink, force: true
super
end

# It does not wipe out BUNDLE_GEMFILE et al
def test_usr2_restart_preserves_bundler_environment
skip_unless_signal_exist? :USR2
Expand All @@ -32,4 +37,53 @@ def test_usr2_restart_preserves_bundler_environment
new_reply = read_body(connection)
assert_match("Gemfile.bundle_env_preservation_test", new_reply)
end

def test_phased_restart_preserves_unspecified_bundle_gemfile
skip_unless_signal_exist? :USR1

@tcp_port = UniquePort.call
env = {
"BUNDLE_GEMFILE" => nil,
"BUNDLER_ORIG_BUNDLE_GEMFILE" => nil
}
set_release_symlink File.expand_path("bundle_preservation_test/version1", __dir__)
cmd = "bundle exec puma -q -w 1 --prune-bundler -b tcp://#{HOST}:#{@tcp_port}"
Dir.chdir(current_release_symlink) do
@server = IO.popen(env, cmd.split, "r")
end
wait_for_server_to_boot
@pid = @server.pid
connection = connect

# Bundler itself sets ENV['BUNDLE_GEMFILE'] to the Gemfile it finds if ENV['BUNDLE_GEMFILE'] was unspecified
initial_reply = read_body(connection)
expected_gemfile = File.expand_path("bundle_preservation_test/version1/Gemfile", __dir__).inspect
assert_equal(expected_gemfile, initial_reply)

set_release_symlink File.expand_path("bundle_preservation_test/version2", __dir__)
start_phased_restart

connection = connect
connection.write "GET / HTTP/1.1\r\n\r\n"
new_reply = read_body(connection)
expected_gemfile = File.expand_path("bundle_preservation_test/version2/Gemfile", __dir__).inspect
assert_equal(expected_gemfile, new_reply)
end

private

def current_release_symlink
File.expand_path "bundle_preservation_test/current", __dir__
end

def set_release_symlink(target_dir)
FileUtils.rm current_release_symlink, force: true
FileUtils.symlink target_dir, current_release_symlink, force: true
end

def start_phased_restart
Process.kill :USR1, @pid

true while @server.gets !~ /booted, phase: 1/
end
end