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

SystemStackError passing value back to Ruby #158

Open
JasonBarnabe opened this issue Feb 3, 2020 · 3 comments
Open

SystemStackError passing value back to Ruby #158

JasonBarnabe opened this issue Feb 3, 2020 · 3 comments

Comments

@JasonBarnabe
Copy link

require 'mini_racer'
context = MiniRacer::Context.new(timeout: 500, max_memory: 20_000_000)
context.attach 'greasyforkSetLogger', ->(value) {}
context.eval(File.read('script.js'))

script.js

Traceback (most recent call last):
       11: from /home/jason/.rbenv/versions/2.6.2/bin/irb:23:in `<main>'
       10: from /home/jason/.rbenv/versions/2.6.2/bin/irb:23:in `load'
        9: from /home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
        8: from (irb):4
        7: from /home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/mini_racer-0.2.9/lib/mini_racer.rb:198:in `eval'
        6: from /home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/mini_racer-0.2.9/lib/mini_racer.rb:198:in `synchronize'
        5: from /home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/mini_racer-0.2.9/lib/mini_racer.rb:200:in `block in eval'
        4: from /home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/mini_racer-0.2.9/lib/mini_racer.rb:307:in `timeout'
        3: from /home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/mini_racer-0.2.9/lib/mini_racer.rb:201:in `block (2 levels) in eval'
        2: from /home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/mini_racer-0.2.9/lib/mini_racer.rb:201:in `eval_unsafe'
        1: from /home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/mini_racer-0.2.9/lib/mini_racer.rb:201:in `new'
SystemStackError (stack level too deep)

If you change greasyforkSetLogger(val); to pass a literal string, there's no error. Something to do with converting the JS object into Ruby?

@SamSaffron
Copy link
Collaborator

What is the minimal repro, can you condense it a bit?

@JasonBarnabe
Copy link
Author

a = {}
a.foo = a
a.bar = new Proxy(function() {}, {
  set: function(obj, prop, val) {
    greasyforkSetLogger(val);
    return true;
  }
});
a.bar.baz = a
Traceback (most recent call last):
	6: from script.rb:4:in `<main>'
	5: from /home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/mini_racer-0.2.9/lib/mini_racer.rb:198:in `eval'
	4: from /home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/mini_racer-0.2.9/lib/mini_racer.rb:198:in `synchronize'
	3: from /home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/mini_racer-0.2.9/lib/mini_racer.rb:200:in `block in eval'
	2: from /home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/mini_racer-0.2.9/lib/mini_racer.rb:307:in `timeout'
	1: from /home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/mini_racer-0.2.9/lib/mini_racer.rb:201:in `block (2 levels) in eval'
/home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/mini_racer-0.2.9/lib/mini_racer.rb:201:in `eval_unsafe': stack level too deep (SystemStackError)

#
# Fatal error in v8::Isolate::Dispose()
# Disposing the isolate that is entered by a thread.
#

script.rb: [BUG] Illegal instruction at 0x00007f20feed9f72
ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0001 p:0000 s:0003 E:000c00 (none) [FINISH]


-- Machine register context ------------------------------------------------
 RIP: 0x00007f20feed9f72 RBP: 0x00007ffe75054960 RSP: 0x00007ffe75054948
 RAX: 0x0000000000000063 RBX: 0x0000558f69148f00 RCX: 0x0000000000000000
 RDX: 0x00007f2102366b80 RDI: 0x00007ffe75052190 RSI: 0x0000000000000000
  R8: 0x0000000000000063  R9: 0x0000000000000063 R10: 0x00007f20fe646a9f
 R11: 0x00007f20feed9f60 R12: 0x0000558f691002f0 R13: 0x0000558f69140fb0
 R14: 0x00007ffe750549b0 R15: 0x0000558f69148f00 EFL: 0x0000000000010202

-- C level backtrace information -------------------------------------------
SEGV received in ILL handler
Aborted (core dumped)

If I don't pass back to Ruby...

a = {}
a.foo = a
a.bar = new Proxy(function() {}, {
  set: function(obj, prop, val) {
    return true;
  }
});
a.bar.baz = a
Traceback (most recent call last):
	7: from script.rb:4:in `<main>'
	6: from /home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/mini_racer-0.2.9/lib/mini_racer.rb:198:in `eval'
	5: from /home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/mini_racer-0.2.9/lib/mini_racer.rb:198:in `synchronize'
	4: from /home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/mini_racer-0.2.9/lib/mini_racer.rb:200:in `block in eval'
	3: from /home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/mini_racer-0.2.9/lib/mini_racer.rb:307:in `timeout'
	2: from /home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/mini_racer-0.2.9/lib/mini_racer.rb:201:in `block (2 levels) in eval'
	1: from /home/jason/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/mini_racer-0.2.9/lib/mini_racer.rb:201:in `eval_unsafe'
JavaScript at JSON.stringify (<anonymous>): TypeError: Converting circular structure to JSON (MiniRacer::RuntimeError)

@JasonBarnabe
Copy link
Author

Even more condensed:

a = {}
a.foo = a
greasyforkSetLogger(a)

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

No branches or pull requests

2 participants