rubyjs / therubyracer

Embed the V8 Javascript Interpreter into Ruby
1.66k stars 193 forks source link

“Maximum call stack size exceeded” error when using fibers #421

Closed denisdefreyne closed 10 months ago

denisdefreyne commented 7 years ago

The following examples raise a “Maximum call stack size exceeded” error:

# a.rb

require 'v8'

context = V8::Context.new

Fiber.new do
  context.eval("console.log('hi')")
end.resume
# b.rb

require 'v8'

context = V8::Context.new

Fiber.new do
  context.enter do
    V8::C::TryCatch() do |trycatch|
      script = V8::C::Script::New("console.log('hi')", '<b>')
      if trycatch.HasCaught()
        puts "HasCaught!"
        p trycatch.Exception.Get("message").to_ruby
      end
    end
  end
end.resume

The output for a.rb:

a.rb:6:in `block in <main>': Maximum call stack size exceeded (V8::Error)

The output for b.rb:

HasCaught!
"Maximum call stack size exceeded"

The error occurs only on Linux; macOS works as expected.

Replacing Fiber.new do X end.resume with X makes the examples work as expected.