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 Jun 3, 2017
1 parent 813eda4 commit 1ae348c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/puma/cluster.rb
Expand Up @@ -111,6 +111,17 @@ def hup
Process.kill "HUP", @pid
rescue Errno::ESRCH
end

def info
Thread.list.each do |thread|
log "Thread TID-#{thread.object_id.to_s(36)} #{thread['label']}"
if thread.backtrace
log thread.backtrace.join("\n")
else
log "<no backtrace available>"
end
end
end
end

def spawn_workers
Expand Down Expand Up @@ -264,6 +275,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 @@ -954,5 +954,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 @@ -102,6 +102,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 1ae348c

Please sign in to comment.