From bb0baa6d7ccfc068b630e4918c64b7e2e3b4bc82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 7 Apr 2014 19:38:47 +0200 Subject: [PATCH] BUGFIX: properly reconnect to the current db after forking --- lib/discourse.rb | 5 +++-- lib/export/exporter.rb | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/discourse.rb b/lib/discourse.rb index 01704e3d468..3f9235ae908 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -238,11 +238,12 @@ module Discourse # after fork, otherwise Discourse will be # in a bad state def self.after_fork + current_db = RailsMultisite::ConnectionManagement.current_db + RailsMultisite::ConnectionManagement.establish_connection(db: current_db) + MessageBus.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 diff --git a/lib/export/exporter.rb b/lib/export/exporter.rb index aeec7419893..96bdaeeb67b 100644 --- a/lib/export/exporter.rb +++ b/lib/export/exporter.rb @@ -144,6 +144,7 @@ module Export pg_dump_running = true Thread.new do + RailsMultisite::ConnectionManagement::establish_connection(db: @current_db) while pg_dump_running message = logs.pop.strip log(message) unless message.blank?