-1

tried to start my rails server, but I got that error

=> Booting Puma
=> Rails 5.1.4 application starting in development 
=> Run `rails server -h` for more startup options
[25156] Puma starting in cluster mode...
[25156] * Version 3.9.1 (ruby 2.4.1-p111), codename: Private Caller
[25156] * Min threads: 5, max threads: 5
[25156] * Environment: development
[25156] * Process workers: 2
[25156] * Preloading application
[25156] * Listening on tcp://0.0.0.0:3000
Exiting
/home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/binder.rb:269:in `initialize': Address already in use - bind(2) for "0.0.0.0" port 3000 (Errno::EADDRINUSE)
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/binder.rb:269:in `new'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/binder.rb:269:in `add_tcp_listener'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/binder.rb:105:in `block in parse'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/binder.rb:88:in `each'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/binder.rb:88:in `parse'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/runner.rb:144:in `load_and_bind'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/cluster.rb:391:in `run'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/launcher.rb:174:in `run'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/rack/handler/puma.rb:69:in `run'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/server.rb:297:in `start'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:44:in `start'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:135:in `block in perform'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `tap'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `perform'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/command/base.rb:63:in `perform'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
    from /home/ahmed/Rails/sample_app/bin/rails:9:in `require'
    from /home/ahmed/Rails/sample_app/bin/rails:9:in `<top (required)>'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
    from /home/ahmed/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
    from /home/ahmed/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
    from /home/ahmed/Rails/sample_app/bin/spring:15:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'

I thought there's some process or something running on port 3000, so I tried to find it using

lsof -wni tcp:3000

but the command returns nothing, so that looks very strange, any solutions?

Update #1

I run this code from another question on stackoverflow and I got that

➜  ~ sudo lsof -iTCP -sTCP:LISTEN -P | grep :3000
ruby      1595        beef-xss   17u  IPv4  32839      0t0  TCP *:3000 (LISTEN)

so I tried

kill -9 1595

and

kill -9 32839

but nothing worked

also I restarted my computer, but the same problem exists, and there are no files inside my "tmp/pids" folders

Update #2

Solved it after uninstalling something called beef-xss using

sudo apt-get --purge remove beef-xss
tadman
  • 208,517
  • 23
  • 234
  • 262
ELTA
  • 1,474
  • 2
  • 12
  • 25
  • Try to run the server in another port like `rails s -p 4000` or restart terminal, If that doesn't work. – fool-dev May 25 '18 at 20:54
  • run `cat /path/to/your/application/tmp/pids/server.pid` which gives you `pid` for ex:- `57285` then `sudo kill -9 57285` – Salil May 25 '18 at 21:42
  • No such file or directory there's something called "beef-xss" running on port 3000, any ways to uninstall it ? , I discovered it using "~ sudo lsof -iTCP -sTCP:LISTEN -P | grep :3000" – ELTA May 25 '18 at 21:56
  • Please don't edit your questions to include "Solved". Stack Overflow will automatically flag any questions as resolved if, and only if, an answer was accepted. If you have a solution, trim that part out and post it as a self-answer you can accept. – tadman May 25 '18 at 22:10

4 Answers4

2

If you are using a Linux operating system

First we will use the fuser command which identifies which processes are using a file or a socket.

fuser -n tcp 3000
3000 / tcp: 7425

The -n parameter is used when we want to identify processes that are using TCP or UDP sockets, in my case I want to know who is using port 3000.

The command returns the pid of the process, with this data and with the help of the ps command we will obtain more information about it.

ps x | grep 7425
7425 pts / 3 Tl 1:15 /home/carlos/.rvm/rubies/ruby-1.9.3-p0/bin/ruby 
script / rails s

With this we see that an instance of the rails test server was hung, to free the port we killed the process using the pid that we already have.

kill -9 7425

And then we see that indeed the process has been completed.

ps x | grep 7425
7973 pts / 3 S + 0:00 grep --color = auto 7425
[1] + Finished (killed) rails s

I hope it will be you useful

The article of the answer http://community.logicalbricks.com/node/103

Andres23Ramirez
  • 647
  • 1
  • 4
  • 14
0

Have you tried to delete the pid files in tmp/pids? If there is anything in the folder try to find a Puma process with pgrep -lf puma and take a look if there's any process of that.

  • my "tmp/pids" are empty, however, I tried to run this command that I got from another answer on stackoverflow and this is what I got ➜ ~ sudo lsof -iTCP -sTCP:LISTEN -P | grep :3000 ................... ruby 1595 beef-xss 17u IPv4 32839 0t0 TCP *:3000 (LISTEN) – ELTA May 25 '18 at 21:30
  • there's something called "beef-xss" running on port 3000, any ways to uninstall it ? , I discovered it using "~ sudo lsof -iTCP -sTCP:LISTEN -P | grep :3000" – ELTA May 25 '18 at 21:56
0

I think you have run another server on the same port and you did not stop this unfortunately and command prompt closed, that's why it's showing this error. SO you can resolve this if you restart your computer.

Just restart your computer then try again.

Also, you can try to remove the files from tmp/pids/

fool-dev
  • 7,671
  • 9
  • 40
  • 54
  • I restarted my computer but the same problem exists, and nothing inside my "tmp/pids/" for all the projects I got – ELTA May 25 '18 at 21:38
  • there's something called "beef-xss" running on port 3000, any ways to uninstall it ? , I discovered it using "~ sudo lsof -iTCP -sTCP:LISTEN -P | grep :3000" – ELTA May 25 '18 at 21:56
0

I run this code from another question on stackoverflow and I got that

➜  ~ sudo lsof -iTCP -sTCP:LISTEN -P | grep :3000
ruby      1595        beef-xss   17u  IPv4  32839      0t0  TCP *:3000 (LISTEN)

so I tried

kill -9 1595

and

kill -9 32839

but nothing worked

also I restarted my computer, but the same problem exists, and there are no files inside my "tmp/pids" folders

Update #2

Solved it after uninstalling something called beef-xss using

sudo apt-get --purge remove beef-xss
ELTA
  • 1,474
  • 2
  • 12
  • 25