Read more

How to get a backtrace if rspec (or any other ruby process) hangs with no output

Martin Schaflitzl
June 27, 2019Software engineer at makandra GmbH

If rspec hangs with no output and you dont get a backtrace neither with --backtrace nor by just killing it with crtl-c,
you can put the following in your spec/spec_helper.rb:

puts "rspec pid: #{Process.pid}"

trap 'USR1' do
  threads = Thread.list

  puts
  puts "=" * 80
  puts "Received USR1 signal; printing all #{threads.count} thread backtraces."

  threads.each do |thr|
    description = thr == Thread.main ? "Main thread" : thr.inspect
    puts
    puts "#{description} backtrace: "
    puts thr.backtrace.join("\n")
  end

  puts "=" * 80
end
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

then kill the process with kill -USR1 <the pid> and you get the backtrace.

(source: https://github.com/rspec/rspec-rails/issues/1353#issuecomment-93173691 Show archive.org snapshot )

Posted by Martin Schaflitzl to makandra dev (2019-06-27 11:29)