DEV: Correct sidekiq logging to avoid thread leak

DEV: Correct sidekiq logging to avoid thread leak

diff --git a/app/jobs/base.rb b/app/jobs/base.rb
index 515a3c8..648cca6 100644
--- a/app/jobs/base.rb
+++ b/app/jobs/base.rb
@@ -67,13 +67,11 @@ module Jobs
       def self.raw_log(message)
         @@logger ||= Logger.new("#{Rails.root}/log/sidekiq.log")
         @@log_queue ||= Queue.new
-        unless @log_thread&.alive?
-          @@log_thread = Thread.new do
-            begin
-              loop { @@logger << @@log_queue.pop }
-            rescue Exception => e
-              Discourse.warn_exception(e, message: "Sidekiq logging thread terminated unexpectedly")
-            end
+        @@log_thread ||= Thread.new do
+          begin
+            loop { @@logger << @@log_queue.pop }
+          rescue Exception => e
+            Discourse.warn_exception(e, message: "Sidekiq logging thread terminated unexpectedly")
           end
         end
         @@log_queue.push(message)

GitHub sha: fe62de68

2 Likes