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
Running apps on 3000, 4000, 5000, 6000, 7000, and beyond. That's plenty of apps. And then one day you get...
Address already in use - bind(2) for "0.0.0.0" port 7000 (Errno::EADDRINUSE)
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 *.*
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.
rl@Robs-MacBook-Pro-2 someapp % netstat -ant | grep LISTEN tcp4 0 0 *.443 *.* LISTEN tcp4 0 0 *.80 *.*
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
Top comments (0)