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

Fix LoadError in CentOS 8 - 'require_relative' should not be necessar… #2381

Merged
merged 1 commit into from Sep 24, 2020

Conversation

joergschray
Copy link
Contributor

@joergschray joergschray commented Sep 24, 2020

…y with recent version of rubygems

Description

The pull request fixes compatibility with CentOS 8: Even for manual installs CentOS 8 separates architecture dependent files from independent ones. Therefore the shared library puma_http11.so ends up in a different directory from puma.rb, which results in the require_relative 'puma/puma_http11' to fail.

Replacing require_relative by require does not change the behavior in case puma_http11.so ends up in the same directory. Apart from that I also consider it best practice in a gem to avoid require_relative altogether. Therefore I also replaced the other
require_relative by require.

Steps to reproduce

Executing the following steps inside a centos:8 docker container:

dnf -y module enable ruby:2.6
dnf -y install ruby ruby-devel gcc make redhat-rpm-config
gem install puma -v5.0.0
puma --version

results in

Traceback (most recent call last):
	9: from /usr/local/bin/puma:23:in `<main>'
	8: from /usr/local/bin/puma:23:in `load'
	7: from /usr/local/share/gems/gems/puma-5.0.0/bin/puma:6:in `<top (required)>'
	6: from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:54:in `require'
	5: from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:54:in `require'
	4: from /usr/local/share/gems/gems/puma-5.0.0/lib/puma/cli.rb:6:in `<top (required)>'
	3: from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:54:in `require'
	2: from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:54:in `require'
	1: from /usr/local/share/gems/gems/puma-5.0.0/lib/puma.rb:13:in `<top (required)>'
/usr/local/share/gems/gems/puma-5.0.0/lib/puma.rb:13:in `require_relative': cannot load such file -- /usr/local/share/gems/gems/puma-5.0.0/lib/puma/puma_http11 (LoadError)

The paths to the relevant files are

  • /usr/local/share/gems/gems/puma-5.0.0/lib/puma.rb
  • /usr/local/lib64/gems/ruby/puma-5.0.0/puma/puma_http11.so

Your checklist for this pull request

  • I have reviewed the guidelines for contributing to this repository.
  • I have added an entry to History.md if this PR fixes a bug or adds a feature. If it doesn't need an entry to HISTORY.md, I have added [changelog skip] or [ci skip] to the pull request title.
  • I have added appropriate tests if this PR fixes a bug or adds a feature.
  • My pull request is 100 lines added/removed or less so that it can be easily reviewed.
  • If this PR doesn't need tests (docs change), I added [ci skip] to the title of the PR.
  • If this closes any issues, I have added "Closes #issue" to the PR description or my commit messages.
  • I have updated the documentation accordingly.
  • All new and existing tests passed, including Rubocop.

@nateberkopec nateberkopec changed the title [changelog skip][ci skip] Fix LoadError in CentOS 8 - 'require_relative' should not be necessar… Fix LoadError in CentOS 8 - 'require_relative' should not be necessar… Sep 24, 2020
@nateberkopec
Copy link
Member

This is a bugfix, so needs a changelog entry. Obviously we don't test on CentOS, but I want to make sure the tests still pass on every other platform anyway.

@nateberkopec nateberkopec added bug waiting-for-changes Waiting on changes from the requestor labels Sep 24, 2020
'require_relative' breaks gem install on CentOS 8 and should not be necessary with recent version of rubygems
@joergschray
Copy link
Contributor Author

Added a changelog entry as requested.

@MSP-Greg
Copy link
Member

@joergschray

Interesting.

I also consider it best practice in a gem to avoid require_relative altogether

Sometimes there is a desire to bypass $LOAD_PATH, especially with vendored files.

Re CentOS, is it generally true that an *.rb will be able to be loaded with require_relative?

@joergschray
Copy link
Contributor Author

Pure ruby files could be loaded via require_relative in CentOS.

However in a gem you usually open up your own namespace. So everything starting with puma/ can always be loaded via require. Of course, a monkey patch will break the require, but that is what a monkey patch is supposed to do.

So unless you put files in a foreign namespace, I do not see a need for using require_relative in a gem.

@nateberkopec
Copy link
Member

Merits of require/require_relative aside, I certainly want CentOS to work. Merging. Thanks for the patch!

@nateberkopec nateberkopec merged commit 93bb1d0 into puma:master Sep 24, 2020
@ehelms
Copy link

ehelms commented Sep 25, 2020

Thanks for fixing this. I've hit the same testing on CentOS 7 as well so it is a wider deployment issue. A 5.0.1 with this fix would be greatly appreciated.

@nateberkopec
Copy link
Member

Yeah I want to get a fix in for #2371, then we'll do 5.0.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug waiting-for-changes Waiting on changes from the requestor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants