DEV: Add DISCOURSE_DUMP_BACKTRACES_ON_UNICORN_WORKER_TIMEOUT env (#27199)

This commit adds a `DISCOURSE_DUMP_BACKTRACES_ON_UNICORN_WORKER_TIMEOUT`
environment that will allow us to dump all backtraces for all threads of
a Unicorn worker 2 seconds before it times out. In development,
backtraces are dumped to `STDOUT` and in production we will dump it to
`unicorn.stdout.log`.

We want to dump all the backtraces to make it easier to identify the
cause of a Unicorn worker timing out.
This commit is contained in:
Alan Guo Xiang Tan
2024-05-27 12:20:38 +08:00
committed by GitHub
parent 3a91a92563
commit 6cafe59c76
2 changed files with 43 additions and 0 deletions

View File

@@ -268,4 +268,9 @@ end
after_fork do |server, worker|
DiscourseEvent.trigger(:web_fork_started)
Discourse.after_fork
Signal.trap("USR2") { puts <<~MSG }
[#{Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%6N")} ##{Process.pid}] Received USR2 signal, dumping backtrace for all threads
#{Thread.list.map { |t| "#{t.backtrace&.join("\n")}" }.join("\n\n")}
MSG
end