debug icon indicating copy to clipboard operation
debug copied to clipboard

rdbg prompt never appears, I can't see what I type (terminal echo) when using bin/dev (Foreman)

Open marshmallowcreme opened this issue 3 years ago • 13 comments

Your environment

  • ruby 3.1.2p20
  • rdbg 1.5.0
  • rails 7.0.3
  • Mac M1 (Apple Silicon)

Describe the bug

I added binding.break to my rails controller, and it breaks as expected. But there is no rdbg prompt, and I can't see what I type in the terminal. And when I do type something, I have to hit enter several times to get a response. And the response is always an error, since it only accepts the first character of what I typed.

marshmallowcreme avatar Jun 10 '22 02:06 marshmallowcreme

Ok, I figured out that this only happens when I'm using bin/dev to run my development server. rails server does not have this problem. So it has something to do with using Foreman to run multiple processes in parallel. Any ideas about how to fix this?

marshmallowcreme avatar Jun 11 '22 14:06 marshmallowcreme

@marshmallowcreme 👋 recently, I came in contact with a Rust-based Foreman cousin: mprocs, which starts described processes and allows you to switch between them, a bit like tmux (or screen). It allows you to interact with the debugger normally (seeing what you wrote).

This may or may not be relevant to your quest.

olleolleolle avatar Jun 12 '22 04:06 olleolleolle

@olleolleolle Thanks. I tried it out, but was unable to see any echo in the terminal window, and no rdbg prompt. Hitting enter would return nothing.

marshmallowcreme avatar Jun 12 '22 14:06 marshmallowcreme

@marshmallowcreme Thanks for trying it out. Perhaps that ruled out something.

olleolleolle avatar Jun 12 '22 14:06 olleolleolle

I'm not sure about the architecture of foreman, but there are issue reports. I want to wait for the person who knows details...

ko1 avatar Jun 25 '22 19:06 ko1

@marshmallowcreme Just to narrow down the cause, do you see a similar issue when using binding.irb?

st0012 avatar Jun 25 '22 22:06 st0012

👋 FWIW I have a similar issue, with a similar machine and Ruby/Rails versions. Neither binding.irb nor debugeer work. Running bin/rails s (i.e. outside of Foreman) allows me to debug.

gjtorikian avatar Jul 20 '22 20:07 gjtorikian

Can I help provide more info for this somehow?

gjtorikian avatar Aug 25 '22 19:08 gjtorikian

An alternative is to have debug listen on a port or socket, and then connect a separate debugger process to that port or socket.

You can update your Procfile.dev to do this for you.

bin/rdbg --port 3001 --open --nonstop --command -- bin/rails server

Then just run a debugger process in another window.

bin/rdbg -A 3001

Having debug and foreman work correctly together might be tough as they are possibly both competing for stdin.

adam12 avatar Aug 26 '22 13:08 adam12

I have the same problem, but the debugger just hangs with bin/rails s, no interactive shell starts and I can't Ctrl-C to stop the server.

zavan avatar Aug 29 '22 13:08 zavan

An alternative is to have debug listen on a port or socket, and then connect a separate debugger process to that port or socket.

You can update your Procfile.dev to do this for you.

bin/rdbg --port 3001 --open --nonstop --command -- bin/rails server

Then just run a debugger process in another window.

bin/rdbg -A 3001

Having debug and foreman work correctly together might be tough as they are possibly both competing for stdin.

@adam12 what is inside bin/rdbg? Thanks

elalemanyo avatar Oct 13 '22 09:10 elalemanyo

what is inside bin/rdbg? Thanks

@elalemanyo It's the debug binstub from bundler. bundler binstubs debug

adam12 avatar Oct 13 '22 13:10 adam12

It is not possible to interact directly with a debug breakpoint (or pry's or byebug's I believe as well) within the foreman process because it is just streaming the output of however many processes you define in your procfile.

You can however, enable remote debugging for debug when you start the rails app, so that you can run your foreman process in one terminal tab/window, and run rdbg -a in a separate terminal tab/window that connects to it.

Here's a blog post with more information: https://dev.to/ayushn21/remote-debugging-in-rails-7-49nh

Edit: Sorry, I missed @adam12's post which is essentially the same solution

waymondo avatar Oct 16 '22 22:10 waymondo