DEV: ensure we never fork v8 contexts from unicorn


DEV: ensure we never fork v8 contexts from unicorn

v8 forking is not supported and can lead to memory leaks.

This commit handles the most common case which is the unicorn master forking

There are still some cases related to backup where we fork, however those forks are usually short lived so the memory leak is not severe, burning the contexts in the master process could break sidekiq or web process that do the actual forking

diff --git a/config/unicorn.conf.rb b/config/unicorn.conf.rb
index e6e2d61..85b2800 100644
--- a/config/unicorn.conf.rb
+++ b/config/unicorn.conf.rb
@@ -69,6 +69,9 @@ before_fork do |server, worker|
+    # V8 does not support forking, make sure all contexts are disposed
+    ObjectSpace.each_object(MiniRacer::Context) { |c| c.dispose }
     # get rid of rubbish so we don't share it

GitHub sha: 76173dea


This commit has been mentioned on Discourse Meta. There might be relevant details there:

Approved #3