mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 11:26:28 +08:00
FIX: properly reset all contexts after forking
Fixes hang on backup
This commit is contained in:
@ -328,6 +328,9 @@ module Discourse
|
|||||||
|
|
||||||
# in case v8 was initialized we want to make sure it is nil
|
# in case v8 was initialized we want to make sure it is nil
|
||||||
PrettyText.reset_context
|
PrettyText.reset_context
|
||||||
|
|
||||||
|
Tilt::ES6ModuleTranspiler.reset_context if defined? Tilt::ES6ModuleTranspiler
|
||||||
|
JsLocaleHelper.reset_context if defined? JsLocaleHelper
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -33,6 +33,10 @@ JS
|
|||||||
ctx
|
ctx
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.reset_context
|
||||||
|
@ctx = nil
|
||||||
|
end
|
||||||
|
|
||||||
def self.v8
|
def self.v8
|
||||||
return @ctx if @ctx
|
return @ctx if @ctx
|
||||||
|
|
||||||
|
@ -165,6 +165,10 @@ module JsLocaleHelper
|
|||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.reset_context
|
||||||
|
@ctx = nil
|
||||||
|
end
|
||||||
|
|
||||||
@mutex = Mutex.new
|
@mutex = Mutex.new
|
||||||
def self.with_context
|
def self.with_context
|
||||||
@mutex.synchronize do
|
@mutex.synchronize do
|
||||||
|
28
script/check_forking.rb
Normal file
28
script/check_forking.rb
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
require File.expand_path("../../config/environment", __FILE__)
|
||||||
|
|
||||||
|
def pretty
|
||||||
|
puts "<before>"
|
||||||
|
puts PrettyText.cook("My pid is #{Process.pid}")
|
||||||
|
end
|
||||||
|
|
||||||
|
Discourse.after_fork
|
||||||
|
pretty
|
||||||
|
|
||||||
|
child = fork do
|
||||||
|
Discourse.after_fork
|
||||||
|
pretty
|
||||||
|
grand_child = fork do
|
||||||
|
Discourse.after_fork
|
||||||
|
pretty
|
||||||
|
puts "try to exit"
|
||||||
|
Process.kill "KILL", Process.pid
|
||||||
|
end
|
||||||
|
puts "before wait 2"
|
||||||
|
Process.wait grand_child
|
||||||
|
puts "after wait 2"
|
||||||
|
Process.kill "KILL", Process.pid
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "before wait 1"
|
||||||
|
Process.wait child
|
||||||
|
puts "after wait 1"
|
Reference in New Issue
Block a user