Skip to content

A platform for community discussion. Free, open, simple.

FIX: Backup/Restore didn't use correct Redis namespace in multisite (#18060)

Gerhard Schlager9ff13cee1438
diff --git a/lib/backup_restore.rb b/lib/backup_restore.rb
index 8e45e1dc8a7..291567a6f0a 100644
--- a/lib/backup_restore.rb
+++ b/lib/backup_restore.rb
@@ -144,12 +144,18 @@ module BackupRestore
end
def self.keep_it_running
+ db = RailsMultisite::ConnectionManagement.current_db
+
# extend the expiry by 1 minute every 30 seconds
Thread.new do
- # this thread will be killed when the fork dies
- while true
- Discourse.redis.expire(running_key, 1.minute)
- sleep 30.seconds
+ RailsMultisite::ConnectionManagement.with_connection(db) do
+ Thread.current.name = "keep_op_running"
+
+ # this thread will be killed when the fork dies
+ while true
+ Discourse.redis.expire(running_key, 1.minute)
+ sleep 30.seconds
+ end
end
end
end
diff --git a/lib/backup_restore/backuper.rb b/lib/backup_restore/backuper.rb
index 6273ff50692..83c10911b39 100644
--- a/lib/backup_restore/backuper.rb
+++ b/lib/backup_restore/backuper.rb
@@ -98,9 +98,13 @@ module BackupRestore
BackupRestore.clear_shutdown_signal!
Thread.new do
- while BackupRestore.is_operation_running?
- exit if BackupRestore.should_shutdown?
- sleep 0.1
+ Thread.current.name = "shutdown_wait"
+
+ RailsMultisite::ConnectionManagement.with_connection(@current_db) do
+ while BackupRestore.is_operation_running?
+ exit if BackupRestore.should_shutdown?
+ sleep 0.1
+ end
end
end
end
diff --git a/lib/backup_restore/system_interface.rb b/lib/backup_restore/system_interface.rb
index 377d40ab6a6..c0d209e5380 100644
--- a/lib/backup_restore/system_interface.rb
+++ b/lib/backup_restore/system_interface.rb
@@ -47,9 +47,13 @@ module BackupRestore
BackupRestore.clear_shutdown_signal!
Thread.new do
- while BackupRestore.is_operation_running?
- exit if BackupRestore.should_shutdown?
- sleep 0.1
+ Thread.current.name = "shutdown_wait"
+
+ RailsMultisite::ConnectionManagement.with_connection(@current_db) do
+ while BackupRestore.is_operation_running?
+ exit if BackupRestore.should_shutdown?
+ sleep 0.1
+ end
end
end
end
diff --git a/spec/lib/backup_restore/system_interface_multisite_spec.rb b/spec/lib/backup_restore/system_interface_multisite_spec.rb
index e9d93e6e3f1..dbc669ca7e8 100644
--- a/spec/lib/backup_restore/system_interface_multisite_spec.rb
+++ b/spec/lib/backup_restore/system_interface_multisite_spec.rb
@@ -36,4 +36,21 @@ RSpec.describe BackupRestore::SystemInterface, type: :multisite do
end
end
end
+
+ describe "#listen_for_shutdown_signal" do
+ it "uses the correct Redis namespace" do
+ test_multisite_connection("second") do
+ BackupRestore.mark_as_running!
+
+ expect do
+ thread = subject.listen_for_shutdown_signal
+ BackupRestore.set_shutdown_signal!
+ thread.join
+ end.to raise_error(SystemExit)
+
+ BackupRestore.clear_shutdown_signal!
+ BackupRestore.mark_as_not_running!
+ end
+ end
+ end
end