mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
BUGFIX: Correct after_fork semantics
After fork SiteSettings was not getting a new process id, causing site settings not to refresh properly in unicorn This code also centralizes the logic
This commit is contained in:
parent
956b14a4ab
commit
f3cc7360e0
8 changed files with 23 additions and 27 deletions
|
@ -10,10 +10,7 @@ end
|
|||
if defined?(PhusionPassenger)
|
||||
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
||||
if forked
|
||||
# We're in smart spawning mode.
|
||||
$redis = DiscourseRedis.new
|
||||
Discourse::Application.config.cache_store.reconnect
|
||||
MessageBus.after_fork
|
||||
Discourse.after_fork
|
||||
else
|
||||
# We're in conservative spawning mode. We don't need to do anything.
|
||||
end
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
# spring binstub rake
|
||||
# spring binstub rspec
|
||||
Spring.after_fork do
|
||||
$redis.client.reconnect
|
||||
Rails.cache.reconnect
|
||||
MessageBus.after_fork
|
||||
Discourse.after_fork
|
||||
end
|
||||
Spring::Commands::Rake.environment_matchers["spec"] = "test"
|
||||
|
|
|
@ -83,8 +83,5 @@ before_fork do |server, worker|
|
|||
end
|
||||
|
||||
after_fork do |server, worker|
|
||||
ActiveRecord::Base.establish_connection
|
||||
$redis.client.reconnect
|
||||
Rails.cache.reconnect
|
||||
MessageBus.after_fork
|
||||
Discourse.after_fork
|
||||
end
|
||||
|
|
|
@ -174,14 +174,7 @@ module BackupRestore
|
|||
end
|
||||
|
||||
def self.after_fork
|
||||
# reconnect to redis
|
||||
$redis.client.reconnect
|
||||
# reconnect the rails cache (uses redis)
|
||||
Rails.cache.reconnect
|
||||
# tells the message we've forked
|
||||
MessageBus.after_fork
|
||||
# /!\ HACK /!\ force sidekiq to create a new connection to redis
|
||||
Sidekiq.instance_variable_set(:@redis, nil)
|
||||
Discourse.after_fork
|
||||
end
|
||||
|
||||
def self.backup_tables_count
|
||||
|
|
|
@ -118,11 +118,7 @@ class Demon::Base
|
|||
end
|
||||
|
||||
def establish_app
|
||||
ActiveRecord::Base.connection_handler.clear_active_connections!
|
||||
ActiveRecord::Base.establish_connection
|
||||
$redis.client.reconnect
|
||||
Rails.cache.reconnect
|
||||
MessageBus.after_fork
|
||||
Discourse.after_fork
|
||||
|
||||
Signal.trap("HUP") do
|
||||
begin
|
||||
|
|
|
@ -234,4 +234,17 @@ module Discourse
|
|||
"/site/read-only"
|
||||
end
|
||||
|
||||
# all forking servers must call this
|
||||
# after fork, otherwise Discourse will be
|
||||
# in a bad state
|
||||
def self.after_fork
|
||||
SiteSetting.after_fork
|
||||
ActiveRecord::Base.establish_connection
|
||||
$redis.client.reconnect
|
||||
Rails.cache.reconnect
|
||||
MessageBus.after_fork
|
||||
# /!\ HACK /!\ force sidekiq to create a new connection to redis
|
||||
Sidekiq.instance_variable_set(:@redis, nil)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -179,6 +179,10 @@ module SiteSettingExtension
|
|||
@@process_id ||= SecureRandom.uuid
|
||||
end
|
||||
|
||||
def after_fork
|
||||
@@process_id = nil
|
||||
end
|
||||
|
||||
def remove_override!(name)
|
||||
provider.destroy(name)
|
||||
current[name] = defaults[name]
|
||||
|
|
|
@ -98,9 +98,7 @@ end
|
|||
|
||||
Spork.each_run do
|
||||
# This code will be run each time you run your specs.
|
||||
$redis.client.reconnect
|
||||
Rails.cache.reconnect
|
||||
MessageBus.after_fork
|
||||
Discourse.after_fork
|
||||
end
|
||||
|
||||
# --- Instructions ---
|
||||
|
|
Loading…
Reference in a new issue