Navigation Menu

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

require 'openssl' causes NameError (uninitialized constant OpenSSL) in 1.0.0 RC14-dev #1614

Closed
deepj opened this issue Mar 11, 2019 · 24 comments

Comments

@deepj
Copy link

deepj commented Mar 11, 2019

Version:

truffleruby 1.0.0-rc14-dev-f6b387c4, like ruby 2.6.1, Interpreted [x86_64-darwin]

To reproduce:

require 'openssl'

Error:

Traceback (most recent call last):
       13: from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/bin/irb:31:in `<main>'
       12: from (irb):2
       11: from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/rubygems/core_ext/kernel_require.rb:54:in `require'
       10: from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/rubygems/core_ext/kernel_require.rb:54:in `require'
        9: from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/openssl.rb:13:in `<top (required)>'
        8: from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/rubygems/core_ext/kernel_require.rb:54:in `require'
        7: from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/rubygems/core_ext/kernel_require.rb:54:in `require'
        6: from ossl.c:1130:in `Init_openssl'
        5: from ruby.c:2096:in `rb_define_module'
        4: from ruby.c:2100:in `rb_define_module_under'
        3: from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/truffle/truffle/cext.rb:1188:in `rb_define_module_under'
        2: from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/truffle/truffle/cext.rb:1188:in `const_get'
        1: from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/truffle/truffle/cext.rb:1188:in `const_missing'
NameError (uninitialized constant OpenSSL)
@deepj
Copy link
Author

deepj commented Mar 11, 2019

@chrisseaton another regression

@chrisseaton
Copy link
Collaborator

I can't reproduce that. Is that file literally what you're running?

@chrisseaton chrisseaton self-assigned this Mar 11, 2019
@chrisseaton
Copy link
Collaborator

That's not even our backtrace format. Can you show a full terminal session?

@nirvdrum
Copy link
Collaborator

@deepj It looks like you're tracking TruffleRuby master. If you've been doing so since before the Ruby 2.6.1 merge, you need to the extensions for the built-in native libraries. I'd recommend just doing a git clean -dxf and rebuilding everything. Please let me know if that clears up your issue.

@deepj
Copy link
Author

deepj commented Mar 11, 2019

This is strange. I can't reproduce the above way in a different terminal session. But I can reproduce it in my specs.

@chrisseaton I can offer a private repo here on Github. It's some old assignment which I upgraded to Ruby 2.6.1 and I tested some stuff in TruffleRuby

@nirvdrum this is a nightly build offered by @chrisseaton to me

@chrisseaton
Copy link
Collaborator

Are you perhaps running a different Ruby as a sub-process?

@deepj
Copy link
Author

deepj commented Mar 11, 2019

I use chruby. In the direction I have .ruby-version set to 2.6.1.

Installed rubies

   ruby-2.5.3
   ruby-2.6.1
*  truffleruby-1.0.0-nightly
   truffleruby-1.0.0-rc11
   truffleruby-1.0.0-rc12
   truffleruby-1.0.0-rc13

@deepj
Copy link
Author

deepj commented Mar 11, 2019

This is an output when I run specs

$ rspec

An error occurred while loading spec_helper.
Failure/Error: require_relative '../app'

NameError:
  uninitialized constant OpenSSL
# ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/truffle/truffle/cext.rb:1188:in `const_missing'
# ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/truffle/truffle/cext.rb:1188:in `const_get'
# ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/truffle/truffle/cext.rb:1188:in `rb_define_module_under'
# ruby.c:2100:in `rb_define_module_under'
# ruby.c:2096:in `rb_define_module'
# ossl.c:1130:in `Init_openssl'
# ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/openssl.rb:13:in `require'
# ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/openssl.rb:13:in `<top (required)>'
# ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/net/https.rb:23:in `require'
# ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/net/https.rb:23:in `<top (required)>'
# ~/.gem/truffleruby/2.6.1/gems/down-4.8.0/lib/down/net_http.rb:4:in `require'
# ~/.gem/truffleruby/2.6.1/gems/down-4.8.0/lib/down/net_http.rb:4:in `<top (required)>'
# ~/.gem/truffleruby/2.6.1/gems/down-4.8.0/lib/down.rb:4:in `require'
# ~/.gem/truffleruby/2.6.1/gems/down-4.8.0/lib/down.rb:4:in `<top (required)>'
# ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/bundler/runtime.rb:81:in `require'
# ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/bundler/runtime.rb:81:in `block (2 levels) in require'
# ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/bundler/runtime.rb:76:in `each'
# ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/bundler/runtime.rb:76:in `block in require'
# ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/bundler/runtime.rb:65:in `each'
# ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/bundler/runtime.rb:65:in `require'
# ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/bundler.rb:114:in `require'
# ./boot.rb:10:in `<top (required)>'
# ./app.rb:3:in `require_relative'
# ./app.rb:3:in `<top (required)>'
# ./spec/spec_helper.rb:5:in `require_relative'
# ./spec/spec_helper.rb:5:in `<top (required)>'

An error occurred while loading ./spec/requests/exchange_spec.rb.
Failure/Error: RSpec.describe App, type: :request do

NameError:
  uninitialized constant App
# ./spec/requests/exchange_spec.rb:5:in `const_missing'
# ./spec/requests/exchange_spec.rb:5:in `<top (required)>'


Finished in 0.011 seconds (files took 14 seconds to load)
0 examples, 0 failures, 2 errors occurred outside of examples

@deepj
Copy link
Author

deepj commented Mar 11, 2019

@chrisseaton would you like have an access to the repo to try to reproduce it?

@deepj
Copy link
Author

deepj commented Mar 12, 2019

@chrisseaton The issue is easily reproducible using this

gem install skylight

Error:

Fetching skylight-core-3.1.4.gem
Fetching skylight-3.1.4.gem
Successfully installed skylight-core-3.1.4
Building native extensions. This could take a while...
ERROR:  Error installing skylight:
	ERROR: Failed to build gem native extension.

    current directory: ~/.gem/truffleruby/2.6.1/gems/skylight-3.1.4/ext
~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/bin/truffleruby -I ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri -r ./siteconf20190312-46381-k9gr7d.rb extconf.rb
~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/truffle/truffle/cext.rb:1188:in `const_missing': uninitialized constant OpenSSL (NameError)
	from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/truffle/truffle/cext.rb:1188:in `const_get'
	from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/truffle/truffle/cext.rb:1188:in `rb_define_module_under'
	from ruby.c:2100:in `rb_define_module_under'
	from ruby.c:2096:in `rb_define_module'
	from ossl.c:1130:in `Init_openssl'
	from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/rubygems/core_ext/kernel_require.rb:117:in `require'
	from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/rubygems/core_ext/kernel_require.rb:117:in `require'
	from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/openssl.rb:13:in `<top (required)>'
	from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/rubygems/core_ext/kernel_require.rb:117:in `require'
	from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/rubygems/core_ext/kernel_require.rb:117:in `require'
	from ~/.gem/truffleruby/2.6.1/gems/skylight-3.1.4/lib/skylight/util/ssl.rb:1:in `<top (required)>'
	from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/rubygems/core_ext/kernel_require.rb:117:in `require'
	from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/rubygems/core_ext/kernel_require.rb:117:in `require'
	from ~/.gem/truffleruby/2.6.1/gems/skylight-3.1.4/lib/skylight/native_ext_fetcher.rb:7:in `<top (required)>'
	from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/rubygems/core_ext/kernel_require.rb:117:in `require'
	from ~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/lib/mri/rubygems/core_ext/kernel_require.rb:117:in `require'
	from extconf.rb:20:in `<main>'
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=~/.rubies/truffleruby-1.0.0-nightly/jre/languages/ruby/bin/truffleruby

extconf failed, exit code 1

Gem files will remain installed in ~/.gem/truffleruby/2.6.1/gems/skylight-3.1.4 for inspection.
Results logged to ~/.gem/truffleruby/2.6.1/extensions/x86_64-darwin/2.6.0/skylight-3.1.4/gem_make.out

@chrisseaton
Copy link
Collaborator

I think I've now seen something similar locally now, but it's a very nonsensical problem. I mean if we're installing gems then openssl is definitely there. Maybe it's being required in a slightly unusual way.

@deepj
Copy link
Author

deepj commented Mar 12, 2019

@chrisseaton This didn't happen in RC13 ...

@chrisseaton
Copy link
Collaborator

Yes I know - it's a bug, it's not intended.

@chrisseaton
Copy link
Collaborator

This appears to be some kind of autoload issue.

@chrisseaton
Copy link
Collaborator

I still don't know exactly why it goes wrong but here's two points of it.

[ruby] INFO: /Users/chrisseaton/Documents/truffleruby/truffleruby/mxbuild/graalvm/jre/languages/ruby/lib/mri/net/http.rb:25: setting up autoload Object::OpenSSL with openssl
....
/Users/chrisseaton/Documents/truffleruby/truffleruby/mxbuild/graalvm/jre/languages/ruby/lib/truffle/truffle/cext.rb:1188:in `const_missing': uninitialized constant OpenSSL (NameError)

@chrisseaton
Copy link
Collaborator

Reproduced by

require 'net/http'
require 'openssl'

@chrisseaton
Copy link
Collaborator

Found the issue - thinking about a fix.

@chrisseaton
Copy link
Collaborator

test.rb:

autoload :Test2, './test2.rb'
require_relative './test2.rb'

test2.rb

p Object.autoload?(:Test2)
p Object.const_defined?(:Test2, false)
p Object.const_get(:Test2, false)
$ ruby test.rb 
nil
false
Traceback (most recent call last):
	3: from test.rb:2:in `<main>'
	2: from test.rb:2:in `require_relative'
	1: from /Users/chrisseaton/Documents/truffleruby/truffleruby/test2.rb:3:in `<top (required)>'
/Users/chrisseaton/Documents/truffleruby/truffleruby/test2.rb:3:in `const_get': uninitialized constant Test2 (NameError)
$ truffleruby-1.0.0-rc13-macos-amd64/bin/ruby test.rb 
"./test2.rb"
true
/Users/chrisseaton/Documents/truffleruby/truffleruby/test2.rb:3:in `const_missing': uninitialized constant Test2 (NameError)
Did you mean?  Test2
	from /Users/chrisseaton/Documents/truffleruby/truffleruby/test2.rb:3:in `const_get'
	from /Users/chrisseaton/Documents/truffleruby/truffleruby/test2.rb:3:in `<top (required)>'
	from test.rb:2:in `require_relative'
	from test.rb:2:in `<main>'
$ jt ruby test.rb 
"./test2.rb"
true
/Users/chrisseaton/Documents/truffleruby/truffleruby/src/main/ruby/core/module.rb:102:in `const_missing': uninitialized constant Test2 (NameError)
	from /Users/chrisseaton/Documents/truffleruby/truffleruby/src/main/ruby/core/module.rb:102:in `const_get'
	from /Users/chrisseaton/Documents/truffleruby/truffleruby/test2.rb:3:in `<top (required)>'
	from test.rb:2:in `require_relative'
	from test.rb:2:in `<main>'

I don't think it's a regression. Maybe something else changed and exposed this bug.

@eregon
Copy link
Member

eregon commented Mar 13, 2019

Yes, what changed is that lib/mri/net/http.rb now autoloads OpenSSL instead of require-ing it directly.

@eregon
Copy link
Member

eregon commented Mar 13, 2019

Actually the diff is:

diff --git a/lib/mri/net/http.rb b/lib/mri/net/http.rb
index 90f051978f..31cbb7a866 100644
--- a/lib/mri/net/http.rb
+++ b/lib/mri/net/http.rb
@@ -20,11 +20,11 @@
 # See Net::HTTP for an overview and examples.
 #

-require 'net/protocol'
+require_relative 'protocol'
 require 'uri'
+autoload :OpenSSL, 'openssl'

 module Net   #:nodoc:
-  autoload :OpenSSL, 'openssl'

So the autoload moved.

@chrisseaton
Copy link
Collaborator

Turns out this was tagged all along

fails:Module#autoload the autoload is removed when the same file is required directly without autoload with a full path
fails:Module#autoload the autoload is removed when the same file is required directly without autoload with a relative path
fails:Module#autoload the autoload is removed when the same file is required directly without autoload in a nested require

@chrisseaton
Copy link
Collaborator

Workaround on the way.

@chrisseaton
Copy link
Collaborator

Worked around in 3a8b2c2.

@eregon
Copy link
Member

eregon commented Mar 20, 2019

I added a proper fix for this in ec974a9.

@eregon eregon self-assigned this Mar 20, 2019
@eregon eregon added this to the 1.0.0-rc14 milestone Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants