Byebug behaving miserably due to multiple unicorn workers in dev

Hello,

I’ve just had a miserable time using byebug within Discourse, due to the default worker_processes being set to 3 in unicorn.conf.rb.

If multiple web workers get stopped by byebug at the same time (for example, you put a byebug line in the drafts#show route, and hit that route twice during the course of development), you end up in a situation where byebug is unable to determine which process you’re typing input for. So, for example, with one stopped process you may type

(byebug) continue

to continue execution, but with two stopped processes you get

(byebug) continue
*** NameError Exception: undefined local variable or method `cntne' for #<Class>

:scream: :scream: :scream:

Even doubling up your input doesn’t really seem to work either:

(byebug) ccoonnttiinnuuee
*** NameError Exception: undefined local variable or method `cntinnue' for #<Class>

This leads to needing to shut down the server completely in order to continue, and happens every time multiple requests are halted by a byebug at once (which, for certain routes, can be quite often)

(NB that this behaviour happens with binding.pry as well)

The workaround is to run

UNICORN_WORKERS=1 bin/unicorn -p 3000

or otherwise set your UNICORN_WORKERS ENV to 1 before booting the app.

I think this could be byebug’s problem (I’ve filed a issue about it), but I wonder what the downsides would be of setting the worker count to 1 automatically in development?

4 Likes

I am not sure I want to reduce unicorn workers it makes dev a bit faster to have multiple, and closer to pro which is good. But this should be fixed if we continue to support byebug, we would need some sort lock file or something to ensure only one session per master process ever goes on.

Personally I never use byebug I just use puts debugging, @tgxworld may use it though, so he may be able to help

1 Like

byebug doesn’t work very well when you have multiple processes printing to STDOUT. I actually have UNICORN_WORKERS=1 and UNICORN_SIDEKIQS=0 in my development env.

4 Likes

I guess in multi process mode it is more hellobug than byebug

4 Likes