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
BUNDLE_GEMFILE is incorrectly set to parent Gemfile in worker processes (when not setting BUNDLE_GEMFILE explicitly) #2133
Comments
Er, 4.3.2 only contains the security issue fix mentioned in the History. |
Oh yeah, that's my bad. The issue is in |
I updated my repro app to demonstrate that the old Gemfile seems to be active in the new workers--removing |
Yikes, I can have a go at fixing this since I broke it in #1893. |
@cjlarose I pulled down your repo and switched to the I see that the Gemfile path does not update as expected, so that seems like a good reproduction. However, when I comment out the one line of substance from #1893, your reproduction fails with:
I think I do see what you are saying, and I will continue to try to write a good test to prove the problem, but I just wanted to let you know that the reproduction isn't quite good enough to go on at the moment. |
@seven1m Yeah I'm sorry that I made the repro kinda hastily. I figured it was better to document what I found quickly before the regression made it into a puma release to limit impact. That said, I think that failure you're seeing is actually the expected behavior. The first version of the application contains Then the script prepares a second version of the application that removes If the new workers are using the new Gemfile, then I expect them to fail when they In retrospect, it probably would have been more clear if I made it so that the new version of the application instead required a new gem that wasn't present in the old version. That's my mistake. Sorry for the confusion. |
Oh, I see! OK that makes sense, thank you. I understand not wanting this bug in a release. 😬 I'll keep poking at it! |
Thanks for taking the time to look into it. I have some notes about what I think might be happening that I thought I could share in case it helps.
I think (haven't verified) that Bundler might preserve the original value of |
@cjlarose I took your approach in this commit and it seems to work. It makes your reproduction repo do what we expect (raise But wow this is a kludge. 😓 And I don't have a good simple testcase to add to the test suite either. @nateberkopec do you have any advice here? Adding a new |
Haha, I don't have a better suggestion as you two have both dug into this issue far more than I have. I agree that this is not a great solution. I'd also point out that #2120 is related here and will have to get merged eventually when working. |
Hello all! I glad to work on #2120 and resolve this… stuff with Bundler. Please, describe for me, what to do and what you're expecting. As I understood, you want to:
Am I right? The main question for me: is it OK? What if |
@AlexWayfer That summary sounds correct. That's how I typically use puma when I want to update my application in a environment that uses mutable infrastructure (reusing existing live servers).
This doesn't work. I think what happens is workers will try to activate the new version of puma, but since an old version is already activated, RubyGems throws an exception. Workers continue to die and spawn and die and spawn. This is actually true of any change in
Yes, typically. This is something devs might have to communicate to operators, unfortunately. If there's a puma upgrade, we have to perform normal or "hot" restarts, not "phased" restarts. |
Also add tests for `GEM_HOME` environment variable preserving. Also drop `BUNDLE_GEMFILE` preserving, resolve puma#2133
@seven1m What is the value of the |
They suggest to add such variable. There is no value of it yet. |
Also add tests for `GEM_HOME` environment variable preserving. Also drop `BUNDLE_GEMFILE` preserving, resolve puma#2133 Also disable local `path` for `bundle install` in CI, it makes `nio4r` unavailable.
Also add tests for `GEM_HOME` environment variable preserving. Also drop `BUNDLE_GEMFILE` preserving, resolve puma#2133 Also disable local `path` for `bundle install` in CI, it makes `nio4r` unavailable. Also install (update) `bundler` in CI, old versions are incompatible.
Also add tests for `GEM_HOME` environment variable preserving. Also drop `BUNDLE_GEMFILE` preserving, resolve puma#2133 Also disable local `path` for `bundle install` in CI, it makes `nio4r` unavailable. Also install (update) `bundler` in CI, old versions are incompatible.
Also add tests for `GEM_HOME` environment variable preserving. Also drop `BUNDLE_GEMFILE` preserving, resolve puma#2133 Also disable local `path` for `bundle install` in CI, it makes `nio4r` unavailable. Also install (update) `bundler` in CI, old versions are incompatible.
I'd love to test this locally, but prune-bundler is looping infinitely for me.
|
@nateberkopec I wasn't able to reproduce that behavior locally on commit e6eb765. Can you try again on my new PR (#2154)? If it fails for you, can you list your Ruby version and Bundler version? |
Describe the bug
Before #1893, if you used
prune_bundler
and startedbundle exec puma
without explicitly settingBUNDLE_GEMFILE
, workers would not have a value set for the environment variableBUNDLE_GEMFILE
. This is desirable when you want workers to use the Gemfile located in the application directory, especially if that directory is different from the directory that you started the puma master process in (such as with a phased restart).After #1893, workers have
BUNDLE_GEMFILE
unexpectedly set to the path of the Gemfile used by the master process. I think this forcesbundler
in the workers to use that Gemfile instead of the one in the worker's working directory as it would if the environment variable was unset.I think the intent of that PR was that if you start your server with
BUNDLE_GEMFILE=Gemfile.rails6 bundle exec puma
, that workers would haveBUNDLE_GEMFILE
set to the same value. But it ignores the fact thatBundler
itself sets a value forENV['BUNDLE_GEMFILE']
even if it wasn't specified at startup time. Workers now end up inheriting this value, when they didn't before.One consequence of this bug is that it is no longer possible to delete from your server the Gemfile that was used when you booted the puma master process. If you do, workers fail with the next phased restart. I imagine there are other bugs related to being able to change gems in the Gemfile for new versions of your application, but I haven't been able to reproduce those.
Puma config:
To Reproduce
I wrote a script that reproduces the error here: https://github.com/cjlarose/puma-phased-restart-could-not-find-gem-errors/tree/regression-1893 (I reused a repo from an unrelated issue)
Before #1893 , workers boot and print
BUNDLE_GEMFILE:
. After that PR, workers boot and printBUNDLE_GEMFILE: /usr/src/releases/1582850222334837300/Gemfile
, referring to the path of the Gemfile that was used by the puma master process.Expected behavior
If
BUNDLE_GEMFILE
was unspecified when you started the master process, it should remain unspecified in the worker processes.Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: