Skip to content

Commit

Permalink
SIGINFO prints thread backtraces
Browse files Browse the repository at this point in the history
  • Loading branch information
nateberkopec committed Sep 2, 2019
1 parent 08f8d19 commit da55bc5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/puma/cluster.rb
Expand Up @@ -269,6 +269,10 @@ def worker(index, master)
server.stop
end

Signal.trap "SIGINFO" do
server.log_thread_status
end

begin
@worker_write << "b#{Process.pid}\n"
rescue SystemCallError, IOError
Expand Down
11 changes: 11 additions & 0 deletions lib/puma/server.rb
Expand Up @@ -1023,5 +1023,16 @@ def self.current
def shutting_down?
@status == :stop || @status == :restart
end

def log_thread_status
Thread.list.each do |thread|
@events.log "Thread TID-#{thread.object_id.to_s(36)} #{thread['label']}"
if thread.backtrace
@events.log thread.backtrace.join("\n")
else
@events.log "<no backtrace available>"
end
end
end
end
end
4 changes: 4 additions & 0 deletions lib/puma/single.rb
Expand Up @@ -113,6 +113,10 @@ def run

@launcher.events.fire_on_booted!

Signal.trap "SIGINFO" do
server.log_thread_status
end

begin
server.run.join
rescue Interrupt
Expand Down

0 comments on commit da55bc5

Please sign in to comment.