Changing the Guardfile leads to "Address already in use"

I found that changing/touching the Guardfile breaks the guard run.

First run of “hanami server” → all works as expected.

Touching/changing the Guardfile leads to:

16:24:38 - WARN - Guardfile changed – _guard-core will exit.
16:24:38 - INFO - Using Guardfile at /home/…/hanami/Guardfile.
16:24:38 - INFO - Puma starting on port 2300 in development environment.
[45593] Puma starting in cluster mode…
[45593] * Puma version: 6.1.1 (ruby 3.2.0-p0) (“The Way Up”)
[45593] * Min threads: 5
[45593] * Max threads: 5
[45593] * Environment: development
[45593] * Master PID: 45593
[45593] * Workers: 2
[45593] * Restarts: (:heavy_check_mark:) hot (:heavy_multiplication_x:) phased
[45593] * Preloading application
/home/…/hanami/vendor/bundle/ruby/3.2.0/gems/puma-6.1.1/lib/puma/binder.rb:335:in `initialize’: Address already in use - bind(2) for “0.0.0.0” port 2300 (Errno::EADDRINUSE)
[…]
16:24:39 - INFO - Guard is now watching at ‘/home/…/hanami’

I then have to stop (Ctrl-C) the server process and restart it.

Pretty sure this is not a Hanami bug but somewhere in Puma or Guard. I could not find anything in Puma or Guard issues that explains it. But it affects new Hanami projects as well. Does anyone have an idea what causes this?

@Signum Help me to understand. Do you do the following?

  1. Run hanami server
  2. While the server is running, you modify the Guardfile.
  3. You get the Errno::EADDRINUSE error

If that is the case, between steps 1 and 2, you should stop the server, modify the Guardfile, then start the server again.

This is how Guard works.

Yes, that’s what I’m doing. If that’s by design and Guard doesn’t like it then I’ll stop/start it while I’m doing changes. I just wondered because Guard is restarting automatically whenever the Guardfile changes. So it felt like something that is supposed to work.

Thanks for the explanation.

:bulb: You can also use Rerun + Overmind which makes for nice workflow without having to worry about restarting the server each time you make a change. Usage is documented in this Hanami demonstration project and here’s the code from the Procfile of that same project if you need it.

IMO, this honestly sounds like a bug worth reporting to guard-puma. I’d definitely encourage you to find a minimal reproduction (i.e. single rackup file only, no Hanami) and share it there.