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_GEMFILE and add a test for it #1893
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
56bbc2d
Preserve BUNDLE_GEMFILE and add a test for it
seven1m a3ed997
Go back to using Bundler.with_original_env
seven1m 4b27762
Gemfile.duplicate is no longer a thing
seven1m dad3e58
Rename test
seven1m 9c2dd28
Skip this test on Windows
seven1m 5e7a6fd
No need to fork
seven1m 7d6780d
Merge remote-tracking branch 'upstream/master'
seven1m 4cfd3b8
Preserve BUNDLE_GEMFILE and other Bundler env vars
seven1m 242c140
Remove unneeded test support file
seven1m f15121f
Update changelog
seven1m 3020316
Run test command without bash
seven1m d89af85
Remove skip for USR2
seven1m c83401c
Move test into separate file
seven1m cbf32d5
Add some logging to help diagnose Travis build failure
seven1m 95bcd05
Is that really running over and over???
seven1m 3be5f32
Yes! It is, but why?
seven1m 9dcd2e3
Don't try to prune_bundler again
seven1m 2ed158e
OMG it works! Remove diagnostic logging.
seven1m 359cb69
When is Bundler loaded by puma-wild?
seven1m 08dc10f
Reenable logging in the test
seven1m 0d020df
Is Bundler defined when using with_clean_env?
seven1m d804495
When is Bundler loaded? (this is nuts)
seven1m 10d4183
Let's see them args!
seven1m d84e0ae
Now let's see the ENV!
seven1m 3d1c5e0
Bundler wins. Just set BUNDLE_GEMFILE manually
seven1m f73cd57
Remove diagnostic logging
seven1m bc4217b
Update changelog
seven1m 62f075f
Add back test skip for platforms without USR2
seven1m 1846ef3
Clarify changelog entry
seven1m File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Gemfile.bundle_env_preservation_test.lock |
1 change: 1 addition & 0 deletions
1
test/bundle_preservation_test/Gemfile.bundle_env_preservation_test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
gem 'puma', path: '../..' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
run lambda { |env| [200, {'Content-Type'=>'text/plain'}, [ENV['BUNDLE_GEMFILE'].inspect]] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require_relative "helper" | ||
require_relative "helpers/integration" | ||
|
||
class TestPreserveBundlerEnv < TestIntegration | ||
def setup | ||
skip NO_FORK_MSG unless HAS_FORK | ||
super | ||
end | ||
|
||
# It does not wipe out BUNDLE_GEMFILE et al | ||
def test_usr2_restart_preserves_bundler_environment | ||
seven1m marked this conversation as resolved.
Show resolved
Hide resolved
|
||
skip_unless_signal_exist? :USR2 | ||
|
||
@tcp_port = UniquePort.call | ||
env = { | ||
# Intentionally set this to something we wish to keep intact on restarts | ||
"BUNDLE_GEMFILE" => "Gemfile.bundle_env_preservation_test", | ||
# Don't allow our (rake test's) original env to interfere with the child process | ||
"BUNDLER_ORIG_BUNDLE_GEMFILE" => nil | ||
} | ||
# Must use `bundle exec puma` here, because otherwise Bundler may not be defined, which is required to trigger the bug | ||
cmd = "bundle exec puma -q -w 1 --prune-bundler -b tcp://#{HOST}:#{@tcp_port}" | ||
Dir.chdir(File.expand_path("bundle_preservation_test", __dir__)) do | ||
@server = IO.popen(env, cmd.split, "r") | ||
end | ||
wait_for_server_to_boot | ||
@pid = @server.pid | ||
connection = connect | ||
initial_reply = read_body(connection) | ||
assert_match("Gemfile.bundle_env_preservation_test", initial_reply) | ||
restart_server connection | ||
new_reply = read_body(connection) | ||
assert_match("Gemfile.bundle_env_preservation_test", new_reply) | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, what happened?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something about the environment in the Travis build was causing
Bundler.with_original_env
to make Puma load in an endless loop. Puma would load, it would callBundler.with_original_env
, then callKernel.exec('puma-wild', ...)
, then the loop would start over again.You can see that loop in this failed build.
I could not reproduce this issue locally, even with the same version of Ubuntu, same version of Ruby, same version of Bundler, and same version of RVM. There are probably other pieces in the environment on the Travis build that I am not aware of and did not fully replicate.
Testing this required, as you can see, pushing many commits to track down the problem.
The
prune_bundler
method is recursive, as you know, and it relies on the linereturn unless defined?(Bundler)
as its terminal case. Something about the Travis environment (I suspect it's RVM) was causing Bundler to be loaded every time the method recursed.As I am out of time to work on this, I went back to the hacky solution that copies the needed env var (
BUNDLE_GEMFILE
) back into the environment after we runBundler.with_clean_env
.It's not my favorite solution, at all. But it meets our needs and should not break anything in other people's environments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Travis is pretty dirty in my experience, so I've switched my repos to other CIs. You can consider something similar too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've moved almost everything to Github Actions, but Ruby 2.2 can't be moved (yet?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ruby 2.2 is no more maintained, even security, but I understand that you want to support its users. But I personally consider its usage dangerous and prefer to drop support from gems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since https://github.com/ruby/setup-ruby/releases/tag/v1.14.0 it is possible to use Ruby 2.2 on GitHub Actions... but it could be that there's something else missing for the Puma test setup (e.g. that version wasn't built with the OpenSSL version we want to test Puma with, I'm sure @MSP-Greg knows about this and maybe even have tried it, I don't have the time to double check it now)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should note that I believe Travis' environment actually saved us from shipping a bug here. Something in that particular environment was causing the Bundler constant to be loaded earlier than anticipated. I suspect it is some RVM magic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One difference between Travis and GitHub Actions is (was) the
bundle install
commandTravis does the following (https://travis-ci.org/puma/puma/jobs/656438353#L885)
Before #2126 (5 days ago),
--path
wasn't used on GitHub Actions, now it is:puma/.github/workflows/ruby.yml
Lines 38 to 39 in 8f28220
Haven't checked if it matters for this particular discussion but thought it was worth mentioning here