1

I'm trying to figure out how to debug threaded web apps in ruby.

The gist below contains a much simplified and trivial app that mirrors the problem I'm having with my project app. I run the application using foreman start and then I try to debug it with a byebug statement in myapp.rb. When I go to the root url in a browser it hits the break point, but doesn't yield control to me in the console, I can't do anything at all. It just shows the breakpoint but I can't type anything into the console, so I can't navigate to other breakpoints etc...

What am I doing wrong?

**Procfile**

web:      bundle exec puma -C ./config/puma.rb

**config.ru**

require_relative 'myapp'
run Sinatra::Application

**myapp.rb** 

require 'sinatra'
require 'byebug'

get '/' do
  message="oh, hello!"
  byebug
  message
end

**puma.rb**

workers 2
threads_count = 5
threads threads_count, threads_count
Riina
  • 530
  • 1
  • 7
  • 19
  • Welcome to Stack Overflow. Don't use a gist or other off-site resource for your code. Links to offsite pages rot, which makes your question worthless to anyone else in the future searching for a similar answer. 'Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve).' – the Tin Man Jul 15 '15 at 17:01

1 Answers1

1

It is probably caused by ruby buffering the output from your webserver. This is describe a little more on the Foreman wiki "Missing Output".

There are two approaches I think. You can stop the buffering before your breakpoint:

$stdout.sync = true
byebug

This works okay for me and you can then debug in the foreman console.

The alternative is to look at remote debugging where you use a debugging server that you can connect to from another process. There's a good answer already covering that in "How to use Byebug with a remote process (e.g., pow)".

Community
  • 1
  • 1
Shadwell
  • 34,314
  • 14
  • 94
  • 99
  • 1
    Thanks for helping realise that the output was being buffered. I thought the debugger wasn't working but it actually was. $stdout.syc change didn't work for me, but remote debugging did the trick. I used remote-pry and it works fine. – Riina Jul 15 '15 at 21:07