DEV Community

RobL
RobL

Posted on

1

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

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Cloudinary image

Optimize, customize, deliver, manage and analyze your images.

Remove background in all your web images at the same time, use outpainting to expand images with matching content, remove objects via open-set object detection and fill, recolor, crop, resize... Discover these and hundreds more ways to manage your web images and videos on a scale.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay