jhawthorn / execjs-fastnode

:zap: A faster Node.JS integration for Ruby/Rails ExecJS
MIT License
51 stars 2 forks source link

Finalizer not running #6

Open sfcgeorge opened 5 years ago

sfcgeorge commented 5 years ago

I believe the finalizer that deletes old contexts is not running because as I added more and more specs (using by capybara-jsdom driver that uses execjs-fastnode) eventually I got out-of-memory errors.

I added a snippet of code like this to manually destroy old contexts and that caused a JSON parse error:

js = ExecJS.compile("function foo() {}")

# ... do stuff with the context ...

runtime = js.instance_variable_get :@runtime
uuid = js.instance_variable_get :@uuid
runtime.vm.delete_context(uuid) # what the finalizer is supposed to do

But that was easy to fix by editing node_piped_runner.js to return [1] instead of 1 as bare values aren't valid top level JSON.

Unfortunately deleting the context still doesn't seem to be freeing up memory and I don't know why. I tried doing global.gc() but that needs the --expose-gc flag but passing flags doesn't seem to work (or I did it wrong). I'm not convince running an extra GC is the answer anyway, but I don't know where to look next to fix the leak.

TLDR:

  1. Finalizer isn't running, not sure why.
  2. node_piped_runner.js needs a tiny tweak to return valid JSON.
  3. don't know... GC or something?