1
0
Fork 0
mirror of https://github.com/rubyjs/mini_racer synced 2023-03-27 23:21:28 -04:00
mini_racer/test/test_forking.rb
Sam Saffron 86bdc6d942
FEATURE: warn more loudly about forked environments
In single_threaded mode MiniRacer will behave far more reasonably if platform
is initialized in the master process.

Sadly this is only a partial solution since we will hang at:

```
#0  0x00007fe6f037e34d in pthread_cond_broadcast@@GLIBC_2.3.2 () from /usr/lib/libpthread.so.0
#1  0x00007fe6ebc15c05 in v8::platform::DelayedTaskQueue::Terminate() ()
   from /home/sam/Source/mini_racer/lib/mini_racer_extension.so
#2  0x00007fe6ebc14dfd in v8::platform::DefaultWorkerThreadsTaskRunner::Terminate() ()
   from /home/sam/Source/mini_racer/lib/mini_racer_extension.so
#3  0x00007fe6ebc13bd6 in v8::platform::DefaultPlatform::~DefaultPlatform() ()
   from /home/sam/Source/mini_racer/lib/mini_racer_extension.so
#4  0x00007fe6ebc13cde in v8::platform::DefaultPlatform::~DefaultPlatform() ()
   from /home/sam/Source/mini_racer/lib/mini_racer_extension.so
#5  0x00007fe6effb0db7 in __run_exit_handlers () from /usr/lib/libc.so.6
```

Likely some more v8 changes are needed to mitigate the heavily forked use
case.
2020-09-15 10:28:54 +10:00

25 lines
558 B
Ruby

$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'mini_racer'
MiniRacer::Platform.set_flags! :single_threaded
@ctx = MiniRacer::Context.new
@ctx.eval("var a = 1+1")
def trigger_gc
puts "a"
ctx = MiniRacer::Context.new
puts "b"
ctx.eval("var a = #{('x' * 100000).inspect}")
puts "c"
ctx.eval("a = undefined")
puts "d"
ctx.isolate.low_memory_notification
puts "f"
puts "done triggering"
end
trigger_gc
Process.wait fork { puts @ctx.eval("a"); @ctx.dispose; puts Process.pid; trigger_gc; puts "done #{Process.pid}" }