DEV Community

RobL
RobL

Posted on

Petty Annoyances #4929

Not every Rails app is run on port 3000, if you're fortunate enough to be managing more than one application over the course of your work you may well have a server boot script.

#!/bin/bash
rails server -b 0.0.0.0 --port=7000 -u puma
Enter fullscreen mode Exit fullscreen mode

Running apps on 3000, 4000, 5000, 6000, 7000, and beyond. That's plenty of apps. And then one day you get...

Image description

Address already in use - bind(2) for "0.0.0.0" port 7000 (Errno::EADDRINUSE)
Enter fullscreen mode Exit fullscreen mode

You'd be forgiven for thinking that you're already running the app in another tab, that's happened before. Nope...

Well, we can netstat and take a look. This is a trimmed down result.

rl@Robs-MacBook-Pro-2 someapp % netstat -ant | grep LISTEN
tcp6       0      0  *.5000                 *.*                    LISTEN     
tcp4       0      0  *.5000                 *.*                    LISTEN     
tcp6       0      0  *.7000                 *.*                    LISTEN     
tcp4       0      0  *.7000                 *.*                    LISTEN     
tcp4       0      0  *.443                  *.*                    LISTEN     
tcp4       0      0  *.80                   *.*                    
Enter fullscreen mode Exit fullscreen mode

Yep it's running as well as something else on port 5000. 443 and 80 (that's puma-dev). So ports 5000, 7000 are running even though I know the apps that are assigned those ports aren't.

Well, I won't keep the suspense. It's Apple AirPlay. If you go to System Preferences > Sharing, you'll it running.

Image description

Untick that.

rl@Robs-MacBook-Pro-2 someapp % netstat -ant | grep LISTEN
tcp4       0      0  *.443                  *.*                    LISTEN     
tcp4       0      0  *.80                   *.*                    

Enter fullscreen mode Exit fullscreen mode

And now our app boots unhindered.

rl@Robs-MacBook-Pro-2 someapp % ./bin/server                    
=> Booting Puma
=> Rails 6.1.7 application starting in development 
=> Run `bin/rails server --help` for more startup options
[DEPRECATED] ActiveSupportBackports should no longer be needed. Please remove!
Puma starting in single mode...
* Puma version: 5.4.0 (ruby 2.7.6-p219) ("Super Flight")
*  Min threads: 5
*  Max threads: 5
*  Environment: development
*          PID: 18359
* Listening on http://0.0.0.0:7000
Use Ctrl-C to stop
Enter fullscreen mode Exit fullscreen mode

Top comments (0)