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

RVM gemset detection broken on RVM 1.29.12 with ruby 2.7 (nginx+passenger) #2420

Open
cure opened this issue Apr 27, 2022 · 0 comments
Open

Comments

@cure
Copy link

cure commented Apr 27, 2022

Issue report

Question 1: What is the problem?

  • What is the expected behavior?

Your answer:

Passenger compiles passenger_native_support.so on demand when running with Ruby 2.7 under RVM with Passenger and Nginx installed separately from packages.

  • What is the actual behavior?

Your answer:

Passenger fails to compile passenger_native_support.so on demand:

App 57582 output:  [passenger_native_support.so] trying to compile for the current user (www-data) and Ruby interpreter...
App 57582 output:      (set PASSENGER_COMPILE_NATIVE_SUPPORT_BINARY=0 to disable)
App 57582 output: Unable to autodetect the currently active RVM gem set name. This could happen if you ran this program using 'sudo' instead of 'rvmsudo'. When using RVM, you're always supposed to use 'rvmsudo' instead of 'sudo!'.
App 57582 output: 
App 57582 output: Please try rerunning this program using 'rvmsudo'. If that doesn't help, please contact this program's author for support.
[ E 2022-04-27 18:11:19.8607 57508/Tk age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /var/www/arvados-api/current: The application process exited prematurely.
  Error ID: 510aa8e0
  Error details saved to: /tmp/passenger-error-AYAmYH.html
  • How can we reproduce it? Please try to provide a sample application (or Virtual Machine) demonstrating the issue. Otherwise, if we can't reproduce it, we might have to ask you a number of followup questions or run certain commands to try and figure out the problem.

Root cause of the problem:

rvm_ruby_string uses 3 strategies to figure out the gemset name:
1. Parsing $GEM_HOME
2. Parsing $GEM_PATH
3. Parsing $LOAD_PATH

By default, nginx removes all environment variables inherited from its parent process (except TZ), cf. http://nginx.org/en/docs/ngx_core_module.html#env. This means that the first two strategies won't work because neither $GEM_HOME or $GEM_PATH is defined out of the box.

On RVM 1.29.12 with Ruby 2.7.2, $LOAD_PATH looks like this for me:

["/usr/local/rvm/rubies/ruby-2.7.2/lib/ruby/site_ruby/2.7.0", "/usr/local/rvm/rubies/ruby-2.7.2/lib/ruby/site_ruby/2.7.0/x86_64-linux", "/usr/local/rvm/rubies/ruby-2.7.2/lib/ruby/site_ruby", "/usr/local/rvm/rubies/ruby-2.7.2/lib/ruby/vendor_ruby/2.7.0", "/usr/local/rvm/rubies/ruby-2.7.2/lib/ruby/vendor_ruby/2.7.0/x86_64-linux", "/usr/local/rvm/rubies/ruby-2.7.2/lib/ruby/vendor_ruby", "/usr/local/rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0", "/usr/local/rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/x86_64-linux"]

Strategy 3 looks for the string rvm/gems/ which is not present in any of the items in $LOAD_PATH, so that doesn't work either.

Updating the check to also look for rvm/rubies/ fixes the detection for me, but I'm not sure that it is a correct solution:

diff --git a/src/ruby_supportlib/phusion_passenger/platform_info/ruby.rb b/src/ruby_supportlib/phusion_passenger/platform_info/ruby.rb
index 3a4fd8e88..2ec2e0bbf 100644
--- a/src/ruby_supportlib/phusion_passenger/platform_info/ruby.rb
+++ b/src/ruby_supportlib/phusion_passenger/platform_info/ruby.rb
@@ -309,10 +309,10 @@ def self.rvm_ruby_string
 
         # That failed too. Try extracting info from from $LOAD_PATH.
         matching_path = $LOAD_PATH.find_all do |item|
-          item.include?("rvm/gems/")
+          item.include?("rvm/gems/") or item.include?("rvm/rubies/")
         end
         if matching_path && !matching_path.empty?
-          subpath = matching_path.to_s.gsub(/^.*rvm\/gems\//, '')
+          subpath = matching_path.to_s.gsub(/^.*rvm\/(gems|rubies)\//, '')
           result = subpath.split('/').first
           return result if result
         end

There is also a workaround:

  1. Tell nginx to load GEM_HOME from the environment (i.e set env GEM_HOME in the main configuration context).
  2. Update the startup script for Nginx to inject GEM_HOME from RVM in the environment when starting Nginx, e.g for systemd (in /etc/systemd/system/nginx.service.d/override.conf):
[Service]
ExecStart=
ExecStart=/bin/bash -a -c "GEM_HOME=`/usr/local/rvm/bin/rvm-exec default env |grep GEM_HOME=|cut -f2 -d=` && /usr/sbin/nginx -g 'daemon on; master_process on;'"

Question 2: Passenger version and integration mode:

Your answer:

open source passenger and libnginx-mod-http-passenger 6.0.13

Question 3: OS or Linux distro, platform (including version):

Your answer:

Debian 11, X86_64 or Ubuntu 18.04, X86_64 with RVM 1.29 (presumably all supported Debian/Ubuntu versions are affected)

Question 4: Passenger installation method:

Your answer:
[ ] RubyGems + Gemfile
[ ] RubyGems, no Gemfile
[ x] Phusion APT repo
[ ] Phusion YUM repo
[ ] OS X Homebrew
[ ] source tarball
[ ] Other, please specify:

Question 5: Your app's programming language (including any version managers) and framework (including versions):

Your answer:

RVM 1.29.12 with Ruby 2.7(.2)

Question 6: Are you using a PaaS and/or containerization? If so which one?

Your answer:

No.

Question 7: Anything else about your setup that we should know?

Your answer:

N/a


We strive for quality and appreciate you taking the time to submit a report! Please note that if you want guaranteed response times and priority issue support we encourage you to join our enterprise customer base. They also provide us with the means to continue our high level of open source support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant