aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Longair <mark@mysociety.org>2013-05-24 15:44:36 +0100
committerMark Longair <mhl@pobox.com>2013-05-24 15:58:36 +0100
commit41ddd29bf6f3e8328e79e4d06b63e08fcfdbf4b6 (patch)
tree5082e9440eab6d5574c4f5a328599ad24fd52fe2
parent8fe4b209e03043d10a05caf5e09676a805bba8a6 (diff)
xapian:rebuild_index: fix for "SSL error: decryption failed or bad record mac"
The connection to the database doesn't survive a fork, but can be re-established if we disconnect beforehand, and use establish_connection in the child after the fork. rebuild_index with safe_rebuild=true is only called as a rake task (i.e. in its own process) so this disconnection and reconnection shouldn't affect the running of the site.
-rw-r--r--vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb
index d45308fec..1e5df8de4 100644
--- a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb
+++ b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb
@@ -711,6 +711,9 @@ module ActsAsXapian
# We fork here, so each batch is run in a different process. This is
# because otherwise we get a memory "leak" and you can't rebuild very
# large databases (however long you have!)
+
+ ActiveRecord::Base.connection.disconnect!
+
pid = Process.fork # XXX this will only work on Unix, tough
if pid
Process.waitpid(pid)
@@ -718,11 +721,10 @@ module ActsAsXapian
raise "batch fork child failed, exiting also"
end
# database connection doesn't survive a fork, rebuild it
- ActiveRecord::Base.connection.reconnect!
else
-
# fully reopen the database each time (with a new object)
# (so doc ids and so on aren't preserved across the fork)
+ ActiveRecord::Base.establish_connection
@@db_path = ActsAsXapian.db_path + ".new"
ActsAsXapian.writable_init
STDOUT.puts("ActsAsXapian.rebuild_index: New batch. #{model_class.to_s} from #{i} to #{i + batch_size} of #{model_class_count} pid #{Process.pid.to_s}") if verbose
@@ -738,6 +740,8 @@ module ActsAsXapian
Kernel.exit! 0
end
+ ActiveRecord::Base.establish_connection
+
end
end
end