Browse Source

Maintenance: Limit dumping of thread status

Tobias Schäfer 2 weeks ago
parent
commit
4df41a3ab3

+ 2 - 2
config/puma.rb

@@ -12,8 +12,8 @@ environment ENV.fetch('RAILS_ENV', 'development')
 preload_app!
 
 # Teach pumactl to use 'SIGWINCH' instead of 'SIGINFO', because the latter is not available on Linux.
-if defined?(Puma::ControlCLI)
-  # Suppress const redefinition warning (can't use silcence_warnings from Rails here).
+if defined?(Puma::ControlCLI) && Zammad::ProcessDebug.enable_thread_status_handler?
+  # Suppress const redefinition warning (can't use silence_warnings from Rails here).
   old_verbose = $VERBOSE
   $VERBOSE = nil
   Puma::ControlCLI::CMD_PATH_SIG_MAP = Puma::ControlCLI::CMD_PATH_SIG_MAP.merge({ 'info' => 'SIGWINCH' }).freeze

+ 3 - 0
doc/developer_manual/cookbook/how-to-debug-zammad-processes.md

@@ -6,6 +6,9 @@ signal to any Zammad service (railsserver, websocket or background worker)
 process, which will cause the process to print the state of its threads to
 STDOUT.
 
+Beware by default this is only available in a production environment. It can be
+forced by setting the environment variable ENFORCE_THREAD_STATUS_HANDLER to "true".
+
 - Find out process ID of Zammad webserver
 
 ```screen

+ 12 - 0
lib/zammad/process_debug.rb

@@ -18,9 +18,21 @@ module Zammad
     end
 
     def self.install_thread_status_handler
+      return if !enable_thread_status_handler?
+
       Signal.trap 'SIGWINCH' do
         Zammad::ProcessDebug.dump_thread_status
       end
     end
+
+    def self.enable_thread_status_handler?
+      return true if %w[1 true].include?(ENV['ENFORCE_THREAD_STATUS_HANDLER'])
+
+      # Explicitly fetch env variable because Rails might not be initialized yet.
+      rails_env = ENV.fetch('RAILS_ENV', 'development')
+      return true if rails_env == 'production'
+
+      false
+    end
   end
 end