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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

"WeakMap key can't be an instance of Integer" breaks google-protobuf 3.15 #2267

Closed
ivoanjo opened this issue Feb 22, 2021 · 5 comments
Closed
Assignees
Milestone

Comments

@ivoanjo
Copy link
Contributor

ivoanjo commented Feb 22, 2021

Hello there! 馃憢

I've been running a few experiments trying to run ddtrace with TruffleRuby.

I found an incompatibility that breaks the latest google-protobuf gem.

Example:

require 'bundler/inline'

puts RUBY_DESCRIPTION

gemfile do
  source 'https://rubygems.org'

  gem 'google-protobuf', '= 3.15.1'
end

require 'google/protobuf'

output on TruffleRuby:

truffleruby 21.0.0.2, like ruby 2.7.2, GraalVM CE Native [x86_64-darwin]
<internal:core> core/weakmap.rb:27:in `check_key_or_value': WeakMap key can't be an instance of Integer (ArgumentError)
	from <internal:core> core/weakmap.rb:34:in `[]='
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/truffle/truffle/cext.rb:847:in `rb_funcall'
	from /Users/ivo.anjo/.rvm/gems/truffleruby-21.0.0.2/gems/google-protobuf-3.15.1/ext/google/protobuf_c/protobuf.c:286:in `ObjectCache_Add'
	from /Users/ivo.anjo/.rvm/gems/truffleruby-21.0.0.2/gems/google-protobuf-3.15.1/ext/google/protobuf_c/defs.c:298:in `DescriptorPool_alloc'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/truffle/truffle/cext.rb:1184:in `__allocate__'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/truffle/truffle/cext.rb:1131:in `new'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/truffle/truffle/cext.rb:1131:in `rb_class_new_instance'
	from class.c:67:in `rb_class_new_instance'
	from /Users/ivo.anjo/.rvm/gems/truffleruby-21.0.0.2/gems/google-protobuf-3.15.1/ext/google/protobuf_c/defs.c:372:in `Defs_register'
	from /Users/ivo.anjo/.rvm/gems/truffleruby-21.0.0.2/gems/google-protobuf-3.15.1/ext/google/protobuf_c/protobuf.c:384:in `Init_protobuf_c'
	from /Users/ivo.anjo/.rvm/gems/truffleruby-21.0.0.2/gems/google-protobuf-3.15.1/lib/google/protobuf.rb:51:in `gem_original_require'
	from /Users/ivo.anjo/.rvm/gems/truffleruby-21.0.0.2/gems/google-protobuf-3.15.1/lib/google/protobuf.rb:51:in `<top (required)>'
	from <internal:core> core/kernel.rb:234:in `gem_original_require'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/runtime.rb:88:in `block in require'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/runtime.rb:58:in `each'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/runtime.rb:58:in `require'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/inline.rb:70:in `block in gemfile'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/settings.rb:124:in `temporary'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/inline.rb:54:in `gemfile'
	from repro-protobuf.rb:5:in `<main>'
<internal:core> core/kernel.rb:236:in `gem_original_require': cannot load such file -- google/2.7/protobuf_c (LoadError)
	from /Users/ivo.anjo/.rvm/gems/truffleruby-21.0.0.2/gems/google-protobuf-3.15.1/lib/google/protobuf.rb:49:in `<top (required)>'
	from <internal:core> core/kernel.rb:234:in `gem_original_require'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/runtime.rb:88:in `block in require'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/runtime.rb:58:in `each'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/runtime.rb:58:in `require'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/inline.rb:70:in `block in gemfile'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/settings.rb:124:in `temporary'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/inline.rb:54:in `gemfile'
	from repro-protobuf.rb:5:in `<main>'
<internal:core> core/kernel.rb:236:in `gem_original_require': cannot load such file -- google-protobuf (LoadError)
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/runtime.rb:74:in `block (2 levels) in require'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/runtime.rb:69:in `each'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/runtime.rb:69:in `block in require'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/runtime.rb:58:in `each'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/runtime.rb:58:in `require'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/inline.rb:70:in `block in gemfile'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/settings.rb:124:in `temporary'
	from /Users/ivo.anjo/.rvm/rubies/truffleruby-21.0.0.2/lib/mri/bundler/inline.rb:54:in `gemfile'
	from repro-protobuf.rb:5:in `<main>'

It looks like MRI allows numbers as keys in WeakMap, but TruffleRuby doesn't:

$ ruby -e "puts RUBY_DESCRIPTION; require 'objspace'; ObjectSpace::WeakMap.new.tap { |it| it[0] = 'boom' }"
truffleruby 21.0.0.2, like ruby 2.7.2, GraalVM CE Native [x86_64-darwin]
<internal:core> core/weakmap.rb:27:in `check_key_or_value': WeakMap key can't be an instance of Integer (ArgumentError)
	from <internal:core> core/weakmap.rb:34:in `[]='
	from -e:1:in `block in <main>'
	from <internal:core> core/kernel.rb:532:in `tap'
	from -e:1:in `<main>'

As usual, let me know if I can provide any more info :)

P.s.: google-protobuf = 3.14.0 seems to work fine so I'm using that as a workaround for now. The google-protobuf changes were done as part of protocolbuffers/protobuf#8184 .

@eregon
Copy link
Member

eregon commented Feb 22, 2021

Thanks for the great report!

Right, this is a change from Ruby 2.7.

CRuby 2.6 also disallowed such keys:

$ ruby -ve "require 'objspace'; ObjectSpace::WeakMap.new.tap { |it| it[0] = 'boom' }"                  
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]
Traceback (most recent call last):
	3: from -e:1:in `<main>'
	2: from -e:1:in `tap'
	1: from -e:1:in `block in <main>'
-e:1:in `[]=': cannot define finalizer for Integer (ArgumentError)

It's unclear why the example with the inline Gemfile does not fail on CRuby 2.6.6 though.

@chrisseaton
Copy link
Collaborator

This blocks us from using a newer grpc as well.

@norswap
Copy link
Contributor

norswap commented Mar 2, 2021

I just started looking into it, I think it should be an easy fix.

chrisseaton added a commit to Shopify/grpc that referenced this issue Mar 9, 2021
See for example oracle/truffleruby#2267 but I think really there's some other issues around headers - also see grpc#25060
graalvmbot pushed a commit that referenced this issue Mar 12, 2021
@norswap
Copy link
Contributor

norswap commented Mar 12, 2021

Well, not that easy :)
Fixed in 1a40956

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