Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Address already in use for puma-dev

Problem

Whenever I try to run

bundle exec puma -C config/puma.rb --port 5000

I keep getting

bundler: failed to load command: puma (/Users/ogirginc/.asdf/installs/ruby/2.7.2/bin/puma)
Errno::EADDRINUSE: Address already in use - bind(2) for "0.0.0.0" port 5000

Tried Things

I have tried anything I can think of or read. Here is the list:

1. Good old restart the mac.

  • Nope.

2. Find PID and kill.

  • Run lsof -wni tcp:5000
COMMAND    PID     USER   FD   TYPE            DEVICE SIZE/OFF NODE NAME
ControlCe 6071 ogirginc   20u  IPv4 0x1deaf49fde14659      0t0  TCP *:commplex-main (LISTEN)
ControlCe 6071 ogirginc   21u  IPv6 0x1deaf49ec4c9741      0t0  TCP *:commplex-main (LISTEN)
  • Kill with sudo kill -9 6071.

  • When I kill it, it is restarted with a new PID.

> lsof -wni tcp:5000
COMMAND    PID     USER   FD   TYPE            DEVICE SIZE/OFF NODE NAME
ControlCe 6071 ogirginc   20u  IPv4 0x1deaf49fde14659      0t0  TCP *:commplex-main (LISTEN)
ControlCe 6071 ogirginc   21u  IPv6 0x1deaf49ec4c9741      0t0  TCP *:commplex-main (LISTEN)

3. Use HTOP to find & kill

  • Filter with puma.
  • Found a match.
PID USER      PRI  NI  VIRT   RES S CPU% MEM%   TIME+  Command
661 ogirginc   17   0  390G  6704 ?  0.0  0.0  0:00.00 /opt/homebrew/bin/puma-dev -launchd -dir ~/.puma-dev -d localhost -timeout 15m0s -no-serve-public-paths
  • Kill it with sudo kill -9 661.
  • Restarted with a new PID.

Additional Info

  • rails version is 5.2.6.
  • puma version is 4.3.8.
  • puma-dev version is 0.16.2.
  • Here are the logs for puma-dev:
2021/10/26 09:48:14 Existing valid puma-dev CA keypair found. Assuming previously trusted.
* Directory for apps: /Users/ogirginc/.puma-dev
* Domains: localhost
* DNS Server port: 9253
* HTTP Server port: inherited from launchd
* HTTPS Server port: inherited from launchd
! Puma dev running...

It feels like I am missing something obvious. Probably, due to lack of understanding some critical & lower parts of puma-dev. I would really appreciate, if this is solved with some simple explanation. Thanks in advance! :)

like image 516
ogirginc Avatar asked Oct 26 '21 07:10

ogirginc


1 Answers

Why

Well, this is interesting. I did not think of searching for lsof's COMMAND column, before.

Turns out, ControlCe means "Control Center" and beginning with Monterey, macOS does listen ports 5000 & 7000 on default.

Solution

  1. Go to System Preferences > Sharing
  2. Uncheck AirPlay Receiver.
  3. Now, you should be able to restart puma as usual.

Source: https://developer.apple.com/forums/thread/682332

like image 50
ogirginc Avatar answered Sep 27 '22 01:09

ogirginc