Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 5 Address already in use - bind(2) for "127.0.0.1" port 3000

After some coding got this error on running rails s:

Address already in use - bind(2) for "127.0.0.1" port 3000 (Errno::EADDRINUSE)

My environment is:

$ rails -v       
Rails 5.0.0
$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]

I've tried:

  1. Create a new project - the same
  2. Checked Rails 4.2 - problem solved
  3. Reinstall rails 5 and ruby - the same problem
  4. lsof -wni tcp:3000 returns me nothing
  5. ps aux | grep "rails" - nothing
  6. ps aux | grep "puma" - nothing
  7. ps aux | grep "ruby" -nothing
  8. Use puma instead of rails s - problem solved
  9. Use rails s -p 3001 - same problem, for other ports too

UPDATED

  1. Use RAILS_ENV=production bundle exec rails s - problem solved

Any suggestions?

like image 251
AKovtunov Avatar asked Jul 19 '16 13:07

AKovtunov


2 Answers

The same process is running somewhere

To see which process used 3000 port and get the process pid type below command

lsof -wni tcp:3000

This will give the process which is using this port

Sample result

process1   12345   0.0  0.0  12343566  1972 s000  R+   11:17AM   0:00.00 grep puma

You can kill this process by typing below command

12345 this is the process ID

kill -9 12345

Now start server again

like image 97
Amol Udage Avatar answered Oct 07 '22 02:10

Amol Udage


The problem appeared because of a bug in Puma's code. Downgrading to the oldest version helped me.

Bug ticket: https://github.com/puma/puma/issues/1022

like image 23
AKovtunov Avatar answered Oct 07 '22 02:10

AKovtunov