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

Update native_support.rb to allow load_native_extension handle invalid byte sequences #2479

Merged
merged 1 commit into from
Mar 16, 2023
Merged

Conversation

drew-wells
Copy link
Contributor

@drew-wells drew-wells commented Mar 16, 2023

We have been getting the following errors from passenger-6.0.17 via RPM from the Passenger REPO on CentOS7 :

App 6968 output: /usr/share/ruby/vendor_ruby/phusion_passenger/native_support.rb:430:in `rescue in load_native_extension': invalid byte sequence in US-ASCII (ArgumentError)
App 6968 output:        from /usr/share/ruby/vendor_ruby/phusion_passenger/native_support.rb:426:in `load_native_extension'
App 6968 output:        from /usr/share/ruby/vendor_ruby/phusion_passenger/native_support.rb:113:in `load_from_load_path'
App 6968 output:        from /usr/share/ruby/vendor_ruby/phusion_passenger/native_support.rb:40:in `try_load'
App 6968 output:        from /usr/share/ruby/vendor_ruby/phusion_passenger/native_support.rb:50:in `start'
App 6968 output:        from /usr/share/ruby/vendor_ruby/phusion_passenger/native_support.rb:443:in `<top (required)>'
App 6968 output:        from <internal:/usr/lib64/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:88:in `require'
App 6968 output:        from <internal:/usr/lib64/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:88:in `require'
App 6968 output:        from /usr/share/ruby/vendor_ruby/phusion_passenger.rb:243:in `require_passenger_lib'
App 6968 output:        from /usr/share/ruby/vendor_ruby/phusion_passenger/preloader_shared_helpers.rb:29:in `<top (required)>'
App 6968 output:        from <internal:/usr/lib64/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:88:in `require'
App 6968 output:        from <internal:/usr/lib64/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:88:in `require'
App 6968 output:        from /usr/share/ruby/vendor_ruby/phusion_passenger.rb:243:in `require_passenger_lib'
App 6968 output:        from /usr/share/passenger/helper-scripts/rack-preloader.rb:57:in `init_passenger'
App 6968 output:        from /usr/share/passenger/helper-scripts/rack-preloader.rb:183:in `<module:App>'
App 6968 output:        from /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'
App 6968 output:        from /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<main>'
App 6968 output: <internal:/usr/lib64/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:88:in `require': linked to incompatible @<D2><EA>^A - /usr/lib64/ruby/vendor_ruby/passenger_native_support.so (LoadError)
App 6968 output:        from <internal:/usr/lib64/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:88:in `require'
App 6968 output:        from /usr/share/ruby/vendor_ruby/phusion_passenger/native_support.rb:427:in `load_native_extension'
App 6968 output:        from /usr/share/ruby/vendor_ruby/phusion_passenger/native_support.rb:113:in `load_from_load_path'
App 6968 output:        from /usr/share/ruby/vendor_ruby/phusion_passenger/native_support.rb:40:in `try_load'
App 6968 output:        from /usr/share/ruby/vendor_ruby/phusion_passenger/native_support.rb:50:in `start'
App 6968 output:        from /usr/share/ruby/vendor_ruby/phusion_passenger/native_support.rb:443:in `<top (required)>'
App 6968 output:        from <internal:/usr/lib64/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:88:in `require'
App 6968 output:        from <internal:/usr/lib64/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:88:in `require'
App 6968 output:        from /usr/share/ruby/vendor_ruby/phusion_passenger.rb:243:in `require_passenger_lib'
App 6968 output:        from /usr/share/ruby/vendor_ruby/phusion_passenger/preloader_shared_helpers.rb:29:in `<top (required)>'
App 6968 output:        from <internal:/usr/lib64/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:88:in `require'
App 6968 output:        from <internal:/usr/lib64/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:88:in `require'
App 6968 output:        from /usr/share/ruby/vendor_ruby/phusion_passenger.rb:243:in `require_passenger_lib'
App 6968 output:        from /usr/share/passenger/helper-scripts/rack-preloader.rb:57:in `init_passenger'
App 6968 output:        from /usr/share/passenger/helper-scripts/rack-preloader.rb:183:in `<module:App>'
App 6968 output:        from /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'
App 6968 output:        from /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<main>'
[ E 2023-03-16 11:49:12.1538 6714/Tz age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /var/www/epro-project5-testing.elysium-ltd.net: The application process exited prematurely.
  Error ID: 80aaf344
  Error details saved to: /tmp/passenger-error-mpkRcW.html

The /usr/lib64/ruby/vendor_ruby/passenger_native_support.so in the RPM is correctly linked to ruby-2.0, but we are using a custom ruby-3.2.1 so the cause of the exception is correct.

Eventually the exception doesn't have any invalid byte sequences in it and passenger starts the application normally and carries on normally until the next web server (Apache) restart. This is random though.

This is caused by the LoadError exception having invalid byte sequences in its message, I have patched the rescue to replace the invalid byte sequences on versions of ruby that support 'String.encode'. I have tested this on all versions of ruby from 1.8.7 to 3.2.1.

This is the exception on ruby-3.1.3

irb(main):001:0> require '/usr/lib64/ruby/vendor_ruby/passenger_native_support.so'
<internal:/usr/lib64/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require': incompatible library version - /usr/lib64/ruby/vendor_ruby/passenger_native_support.so (LoadError)
	from <internal:/usr/lib64/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from (irb):1:in `<main>'
	from /usr/lib64/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
	from /usr/bin/irb31:25:in `load'
	from /usr/bin/irb31:25:in `<main>'

This is the exception on ruby-3.2.1

irb(main):001:0> require '/usr/lib64/ruby/vendor_ruby/passenger_native_support.so'
<internal:/usr/lib64/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:88:in `require': linked to incompatible \xC1- /usr/lib64/ruby/vendor_ruby/passenger_native_support.so (LoadError)
	from <internal:/usr/lib64/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:88:in `require'
	from (irb):1:in `<main>'
	from /usr/lib64/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'
	from /usr/bin/irb32:25:in `load'
	from /usr/bin/irb32:25:in `<main>'

So, it looks like only ruby-3.2.x could possibly generate an invalid byte sequence.

Allow load_native_extension to handle invalid byte sequences in the LoadError exception
@CamJN
Copy link
Contributor

CamJN commented Mar 16, 2023

This looks great, in order to merge it I need you to fill out the contributor agreement. And while you don't have to do this in order for me to merge this PR, it might be a good idea to file a bug with Ruby since it seems they have a non deterministic string encoding bug.

@drew-wells
Copy link
Contributor Author

I have filled out the contributor agreement. I'll have a look at filing a bug with Ruby as well.

@CamJN CamJN merged commit 8b70688 into phusion:stable-6.0 Mar 16, 2023
@CamJN
Copy link
Contributor

CamJN commented Mar 16, 2023

Thanks so much!

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

Successfully merging this pull request may close these issues.

None yet

2 participants