A platform for community discussion. Free, open, simple.
FIX: Ensure we dispose of MiniRacer::Context before forking daemons (#28361)
Alan Guo Xiang Tan10ff0ee0cc00
diff --git a/config/unicorn.conf.rb b/config/unicorn.conf.rbindex b8c549bc0fc..13c3f4eaf16 100644--- a/config/unicorn.conf.rb+++ b/config/unicorn.conf.rb@@ -64,15 +64,7 @@ initialized = falsebefore_fork do |server, worker|unless initializedDiscourse.preload_rails!-- # 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- # longer term we will use compact! here- GC.start- GC.start- GC.start+ Discourse.before_forkinitialized = truediff --git a/lib/demon/base.rb b/lib/demon/base.rbindex 5ab23c2a3ad..61b7682e6e5 100644--- a/lib/demon/base.rb+++ b/lib/demon/base.rb@@ -154,6 +154,8 @@ class Demon::Baseenddef run+ Discourse.before_fork if defined?(Discourse)+@pid =fork doProcess.setproctitle("discourse #{self.class.prefix}")@@ -161,6 +163,7 @@ class Demon::Baseestablish_appafter_forkend+write_pid_fileenddiff --git a/lib/discourse.rb b/lib/discourse.rbindex 53ab64aecee..c1dafbfedd7 100644--- a/lib/discourse.rb+++ b/lib/discourse.rb@@ -896,6 +896,20 @@ module Discourse"/site/read-only"end+ # all forking servers must call this+ # before forking, otherwise the forked process might+ # be in a bad state+ def self.before_fork+ # 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+ # longer term we will use compact! here+ GC.start+ GC.start+ GC.start+ end+# all forking servers must call this# after fork, otherwise Discourse will be# in a bad state