# 在开发环境中，由于多个 Unicorn 工作进程导致 Byebug 表现异常

**URL:** https://meta.discourse.org/t/byebug-behaving-miserably-due-to-multiple-unicorn-workers-in-dev/96184
**Category:** Development
**Created:** [2018年九月2日 06:07 UTC](https://meta.discourse.org/t/byebug-behaving-miserably-due-to-multiple-unicorn-workers-in-dev/96184 "2018-09-02T06:07:54Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![gdpelican](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gdpelican/32/81308_2.png) [@gdpelican](https://meta.discourse.org/u/gdpelican)
#### Post date: [2018年九月2日 06:07 UTC](https://meta.discourse.org/t/byebug-behaving-miserably-due-to-multiple-unicorn-workers-in-dev/96184/1 "2018-09-02T06:07:54Z")

</div>

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

```plaintext
(byebug) continue

```

to continue execution, but with two stopped processes you get

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

```

😱 😱 😱

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

```plaintext
(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

```plaintext
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](https://github.com/deivid-rodriguez/byebug/issues/487) about it), but I wonder what the downsides would be of setting the worker count to 1 automatically in development?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2018年九月2日 22:49 UTC](https://meta.discourse.org/t/byebug-behaving-miserably-due-to-multiple-unicorn-workers-in-dev/96184/2 "2018-09-02T22:49:12Z")

</div>

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

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [2018年九月3日 00:04 UTC](https://meta.discourse.org/t/byebug-behaving-miserably-due-to-multiple-unicorn-workers-in-dev/96184/3 "2018-09-03T00:04:07Z")

</div>

`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.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2018年九月3日 01:12 UTC](https://meta.discourse.org/t/byebug-behaving-miserably-due-to-multiple-unicorn-workers-in-dev/96184/4 "2018-09-03T01:12:57Z")

</div>

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