DEV: Fix duplicated logging of unicorn worker backtraces (#30178)

In 6cafe59c76, we added a monkey patch to
`Unicorn::HtppServer#murder_lazy_workers` to log a message and send a
`USR2` signal to the Unicorn worker process when they Unicorn worker
process is 2 seconds away from being timed out by the Unicorn master
process. However, we ended up loggging multiple messages and sending
multiple USR2 signal during the 2 seconds before the Unicorn worker
process hit the time out.

To overcome this problem, we will now set an instance variable on the
`Unicorn::Worker` instance and use it to ensure that the log message is
only logged once and USR2 signal to the Unicorn worker process is only
sent one as well.
This commit is contained in:
Alan Guo Xiang Tan 2024-12-10 06:47:33 +08:00 committed by GitHub
parent 1670ffe82d
commit 2f65f36cae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -131,9 +131,12 @@ before_fork do |server, worker|
tmp = @timeout - diff
# START MONKEY PATCH
if tmp < 2
logger.error "worker=#{worker.nr} PID:#{wpid} running too long " \
"(#{diff}s), sending USR2 to dump thread backtraces"
if tmp < 2 && !worker.instance_variable_get(:@timing_out_logged)
logger.error do
"worker=#{worker.nr} PID:#{wpid} running too long (#{diff}s), sending USR2 to dump thread backtraces"
end
worker.instance_variable_set(:@timing_out_logged, true)
kill_worker(:USR2, wpid)
end
# END MONKEY PATCH