ruby-amqp / bunny

Bunny is a popular, easy to use, mature Ruby client for RabbitMQ
Other
1.39k stars 303 forks source link

NameError: uninitialized constant OpenSSL::SSL::TLS1_3_VERSION (bunny-2.20.0, ruby 2.6) #645

Closed doconnor-clintel closed 1 year ago

doconnor-clintel commented 1 year ago

Via dependabot;

NameError: uninitialized constant OpenSSL::SSL::TLS1_3_VERSION
--
  | /var/lib/buildkite-agent/.bundlecache/ruby/2.6.0/gems/bunny-2.20.0/lib/bunny/transport.rb:34:in `<class:Transport>'
  | /var/lib/buildkite-agent/.bundlecache/ruby/2.6.0/gems/bunny-2.20.0/lib/bunny/transport.rb:16:in `<module:Bunny>'
  | /var/lib/buildkite-agent/.bundlecache/ruby/2.6.0/gems/bunny-2.20.0/lib/bunny/transport.rb:14:in `<main>'
  | /var/lib/buildkite-agent/.bundlecache/ruby/2.6.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
  | /var/lib/buildkite-agent/.bundlecache/ruby/2.6.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
  | /var/lib/buildkite-agent/.bundlecache/ruby/2.6.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
  | /var/lib/buildkite-agent/.bundlecache/ruby/2.6.0/gems/bunny-2.20.0/lib/bunny/session.rb:5:in `<main>'
  | /var/lib/buildkite-agent/.bundlecache/ruby/2.6.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
  | /var/lib/buildkite-agent/.bundlecache/ruby/2.6.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
  | /var/lib/buildkite-agent/.bundlecache/ruby/2.6.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
  | /var/lib/buildkite-agent/.bundlecache/ruby/2.6.0/gems/bunny-2.20.0/lib/bunny.rb:27:in `<main>'
  | /var/lib/buildkite-agent/.bundlecache/ruby/2.6.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
  | /var/lib/buildkite-agent/.bundlecache/ruby/2.6.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
  | /var/lib/buildkite-agent/builds/ip-172-31-46-227/clintel/cr-tests/config/application.rb:7:in `<top (required)>'
  | /var/lib/buildkite-agent/builds/ip-172-31-46-227/clintel/cr-tests/Rakefile:4:in `require'
  | /var/lib/buildkite-agent/builds/ip-172-31-46-227/clintel/cr-tests/Rakefile:4:in `<top (required)>'
  | /var/lib/buildkite-agent/.bundlecache/ruby/2.6.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'

Strangely, this constant should probably be available even as far back as Ruby 2.5.1: https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html

It might just be a load order issue on our side of things; however Bunny 2.19.0 doesn't appear to experience the issue.

michaelklishin commented 1 year ago

What happens on Ruby 2.7 or 3.x?

michaelklishin commented 1 year ago

I am not particularly interested in spending time on Ruby 2.6 compatibility, if 2.7 and 3.x do not run into this, I'd simply bump the minimum supported version for new releases.

Also, we need a way to reproduce since quite obviously only you have access to your CI env.

michaelklishin commented 1 year ago

Looking at the code in transport.rb:

begin
  require "openssl"
rescue LoadError => _le
  $stderr.puts "Could not load OpenSSL"
end

makes me wonder if the OpenSSL version on your CI host is too old to support TLS 1.3, and thus the OpenSSL Ruby extension infers that and doesn't make the constant available.

Older Ruby versions and cutting edge TLS won't necessarily play well together. It took JVM and Erlang TLS implementations a few years to iron out TLS 1.3 support.

I could not reproduce on 2.7 or 3.x, and could not build Ruby 2.6 on ARM64 locally. Trying out a Docker image next.

michaelklishin commented 1 year ago

I cannot reproduce using ruby:2.6 and ruby:slim (3.x) images:

irb(main):001:0> require "openssl"
=> true
irb(main):002:0> OpenSSL::SSL::TLS1_3_VERSION
=> 772
irb(main):003:0> RUBY_VERSION
=> "2.6.10"
irb(main):001:0> OpenSSL::SSL::TLS1_3_VERSION
(irb):1:in `<main>': uninitialized constant OpenSSL (NameError)
    from /usr/local/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
    from /usr/local/bin/irb:25:in `load'
    from /usr/local/bin/irb:25:in `<main>'
irb(main):002:0> require "openssl"
=> true
irb(main):003:0> OpenSSL::SSL::TLS1_3_VERSION
=> 772
irb(main):004:0> RUBY_VERSION
=> "3.1.3"