Code Monkey home page Code Monkey logo

Comments (7)

seanmakesgames avatar seanmakesgames commented on July 17, 2024

Looks like my workers are working too long without a garbage collection. If GC triggers inside a proc which has GVL, I'm sure some other c-code somewhere is doing the allocation that's causing the error. I'm pretty sure I can fix the issue on my side, by making sure to explicitly call GC.start before doing an eval.
I'm sure there are some cases where attached procs might alloc enough memory on their own during an eval to cause a GC.

Here's the test case:

  def test_start_gc
    context = MiniRacer::Context.new(timeout: 10)
    context.attach("echo", proc{|msg| GC.start; msg})
    GC.disable
    100.times { 'foo' } # alloc a handful of objects
    GC.enable
    assert_equal("foo", context.eval("while(true) echo('foo');"))
  end

from mini_racer.

seanmakesgames avatar seanmakesgames commented on July 17, 2024

adding the GC.start before I run run any eval has mostly prevented the crashes, but adds 100ms to all of my execution times.

In fact, now that I'm thinking about it, I haven't gotten a c-level crash in a few days... of any kind.

from mini_racer.

seanmakesgames avatar seanmakesgames commented on July 17, 2024

I moved garbage collection (GC.start) to after the eval and the crashes have come back, but in less numbers. Feel like this is a really strong indicator for all of the issues. I'm going to disable garbage collection around the eval call and see if crashes go away again.

from mini_racer.

seanmakesgames avatar seanmakesgames commented on July 17, 2024

I have confirmed that under stress testing there is ZERO instances of c-level crashes (or strange ruby crashes) when garbage collection is turned off during js eval. I'm closing and referencing this issue as a 'cause'

example code:

                GC.disable
                result["retval"] = ctx.eval(code_to_execute)
                GC.enable

from mini_racer.

SamSaffron avatar SamSaffron commented on July 17, 2024

Let me know how this goes:

6fbec25

Pretty sure I fixed this issue.

from mini_racer.

seanmakesgames avatar seanmakesgames commented on July 17, 2024

Today is launch day. I won't be able to test for a while probably. Have you run the 'tight-loop' test? (I don't have time rn)
With or without the GC.start used to cause problems if I remember correctly

  def test_segfault
    5000.times do
      GC.start

      context = MiniRacer::Context.new(timeout: 5)
      context.attach("echo", proc{|msg| msg.to_sym.to_s})
      assert_raises(MiniRacer::EvalError) do
        context.eval("while(true) echo('foo');")
      end
    end
  end

from mini_racer.

SamSaffron avatar SamSaffron commented on July 17, 2024

OK, closing this, I think this is fixed in the pre-release

from mini_racer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.