truffleruby icon indicating copy to clipboard operation
truffleruby copied to clipboard

Intermittent problem with Oj gem

Open gogainda opened this issue 3 years ago • 2 comments

Gemfile:

# frozen_string_literal: true

source 'https://rubygems.org'

gem 'rake', require: false
gem 'oj'

oj-test.rb

require 'oj'
for i in 1..10_000_000_000 do
  puts Oj.load('{"Concerts":[{"ConcertId":"id-1"},{"ConcertId":"id-2"}]}', :mode=>:compat, :symbol_keys=>false, :empty_string=>false)
end

How to run

bundle exec ruby oj-test.rb

Eventually it will fail with:

/Users/novoi/.rubies/truffleruby-dev/lib/truffle/truffle/cext.rb:1115:in `rb_exc_raise': Hash/Object not terminated (after Concerts) at line 1, column 55 [parse.c:1151] in '{"Concerts":[{"ConcertId":"id-1"},{"ConcertId":"id-2"}]} (EncodingError)
	from exception.c:29:in `rb_exc_raise'
	from /Users/novoi/.rubies/truffleruby-dev/lib/gems/gems/oj-3.13.21/ext/oj/parse.c:1192:in `oj_pi_parse'
	from /Users/novoi/.rubies/truffleruby-dev/lib/gems/gems/oj-3.13.21/ext/oj/compat.c:238:in `oj_compat_parse'
	from /Users/novoi/.rubies/truffleruby-dev/lib/gems/gems/oj-3.13.21/ext/oj/oj.c:1070:in `load'
	from /Users/novoi/.rubies/truffleruby-dev/lib/truffle/truffle/cext_ruby.rb:41:in `load'
	from oj-test.rb:3:in `block in <main>'
	from oj-test.rb:2:in `each'
	from oj-test.rb:2:in `<main>'

Could be related to https://github.com/ohler55/oj/issues/293

Affected gems

aws-sdk-ruby

gogainda avatar Oct 06 '22 18:10 gogainda

Thank you for the report. Can you also reproduce it on CRuby or only on TruffleRuby? It sounds like it could be an issue in Oj.

eregon avatar Oct 07 '22 10:10 eregon

for CRuby I cannot reproduce it. Interestingly this test fails only when executed with bundle exec, so it could be combination of oj + bundle

gogainda avatar Oct 07 '22 10:10 gogainda

Cannot reproduce the issue on the TruffleRuby master. Was waiting for 10M iterations and then stopped the script.

andrykonchin avatar Jul 01 '24 19:07 andrykonchin