Skip to content

Conversation

@CamJN
Copy link
Contributor

@CamJN CamJN commented Dec 11, 2024

What was the end-user or developer problem that led to this PR?

If a ruby process has changed it's name for ease of understanding in ps or top output, and then loads bundler, but the correct bundler is not installed, then the error message the user sees is very confusing.

Links:
phusion/passenger#2567
phusion/passenger#2577

What is your fix for the problem, implemented in this PR?

Use Process.argv0 instead of $PROGRAM_NAME because $PROGRAM_NAME is liable to be changed but Process.argv0 is not.

Links:

Make sure the following tasks are checked

Sorry I didn't write any tests, I have no idea how to setup the required failing environment in your test environment. I've created a minimal reproduction environment below, which I used to verify the fix.

If you create all of these files, then run the following commands, you can trigger the bad error message, and then if you patch the /usr/local/lib/ruby/site_ruby/3.2.0/bundler/self_manager.rb file in the container and run ruby test.rb again, you will get a good error message.

docker build -t bundler_bug .
docker run -it bundler_bug
docker run -it bundler_bug bash
# edit /usr/local/lib/ruby/site_ruby/3.2.0/bundler/self_manager.rb
ruby test.rb

Dockerfile:

FROM ruby:3.2.6

WORKDIR /root
COPY test.rb /root/test.rb
COPY Gemfile /root/Gemfile
COPY Gemfile.lock /root/Gemfile.lock

RUN gem update --system
RUN bundle config set --local deployment "true"
RUN bundle config set --local path vendor/ruby
RUN bundle install
RUN rm -rf /root/vendor/ruby/ruby/3.2.0/gems/bundler-2.5.12

CMD ["ruby", "test.rb"]

Gemfile:

# frozen_string_literal: true

source "https://rubygems.org"

ruby '3.2.6'

Gemfile.lock:

GEM
  remote: https://rubygems.org/
  specs:

PLATFORMS
  arm64-darwin-23
  ruby

DEPENDENCIES

RUBY VERSION
   ruby 3.2.6p234

BUNDLED WITH
   2.5.12

test.rb

#!/usr/bin/env ruby
$0 = "this is the program name"
require 'bundler/setup'

@welcome
Copy link

welcome bot commented Dec 11, 2024

Thanks for opening a pull request and helping make RubyGems and Bundler better! Someone from the RubyGems team will take a look at your pull request shortly and leave any feedback. Please make sure that your pull request has tests for any changes or added functionality.

We use GitHub Actions to test and make sure your change works functionally and uses acceptable conventions, you can review the current progress of GitHub Actions in the PR status window below.

If you have any questions or concerns that you wish to ask, feel free to leave a comment in this PR or join our #rubygems or #bundler channel on Slack.

For more information about contributing to the RubyGems project feel free to review our CONTRIBUTING guide

@deivid-rodriguez deivid-rodriguez changed the title Fix self_manager.rb Fix restarting with locked version when $PROGRAM_NAME has been changed Dec 12, 2024
@deivid-rodriguez
Copy link
Contributor

Thanks a lot, this must have been really hard to debug, so good to save that for others from now on :)

I tried adding a spec to cover the fix.

@CamJN
Copy link
Contributor Author

CamJN commented Dec 12, 2024

Thanks for the spec, I appreciate it!

Use Process.argv0 instead of $PROGRAM_NAME because $PROGRAM_NAME is
liable to be changed but Process.argv0 is not.
@deivid-rodriguez
Copy link
Contributor

Thanks so much!

@deivid-rodriguez deivid-rodriguez merged commit 80c1e7e into ruby:master Dec 13, 2024
83 checks passed
@CamJN
Copy link
Contributor Author

CamJN commented Dec 13, 2024

No, thank you! This will save me a lot of headaches in the future, I'm sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants