0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rails sでサーバーを再起動する際にのAddress already in useエラーの解決

0
Posted at

背景

開発の途中でサーバーが詰まられていました。
Ctrl + cでも止めらないので、Ctrl + zで強制退出しました。
サーバーを再起動するために、まずrailsのプロセスを停止します。

ps aux | grep rails
sudo kill -9 [pid_number]

あとはpidsを確認します。

rm -rf /tmp/pids/server.pid

その後はrails sで再起動します。

事象

sudo bundle exec rail s

Railsサーバーを起動したら、下記のエラーが発生しました。

/Users/longlong.li/.bundle/ruby/2.3.0/gems/puma-3.12.1/lib/puma/binder.rb:273:in `initialize': Address already in use - bind(2) for "127.0.0.1" port 3000 (Errno::EADDRINUSE)
	from /Users/longlong.li/.bundle/ruby/2.3.0/gems/puma-3.12.1/lib/puma/binder.rb:273:in `new'
	from /Users/longlong.li/.bundle/ruby/2.3.0/gems/puma-3.12.1/lib/puma/binder.rb:273:in `add_tcp_listener'
	from /Users/longlong.li/.bundle/ruby/2.3.0/gems/puma-3.12.1/lib/puma/binder.rb:267:in `block in add_tcp_listener'
	from /Users/longlong.li/.bundle/ruby/2.3.0/gems/puma-3.12.1/lib/puma/binder.rb:266:in `each'
	from /Users/longlong.li/.bundle/ruby/2.3.0/gems/puma-3.12.1/lib/puma/binder.rb:266:in `add_tcp_listener'
	from /Users/longlong.li/.bundle/ruby/2.3.0/gems/puma-3.12.1/lib/puma/binder.rb:106:in `block in parse'
	from /Users/longlong.li/.bundle/ruby/2.3.0/gems/puma-3.12.1/lib/puma/binder.rb:90:in `each'
	from /Users/longlong.li/.bundle/ruby/2.3.0/gems/puma-3.12.1/lib/puma/binder.rb:90:in `parse'
	from /Users/longlong.li/.bundle/ruby/2.3.0/gems/puma-3.12.1/lib/puma/runner.rb:153:in `load_and_bind'
	from /Users/longlong.li/.bundle/ruby/2.3.0/gems/puma-3.12.1/lib/puma/single.rb:98:in `run'
	from /Users/longlong.li/.bundle/ruby/2.3.0/gems/puma-3.12.1/lib/puma/launcher.rb:186:in `run'
	from /Users/longlong.li/.bundle/ruby/2.3.0/gems/puma-3.12.1/lib/rack/handler/puma.rb:73:in `run'
	from /Users/longlong.li/.bundle/ruby/2.3.0/gems/rack-1.6.11/lib/rack/server.rb:287:in `start'
	from /Users/longlong.li/.bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/server.rb:80:in `start'
	from /Users/longlong.li/.bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:80:in `block in server'
	from /Users/longlong.li/.bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `tap'
	from /Users/longlong.li/.bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `server'
	from /Users/longlong.li/.bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
	from /Users/longlong.li/.bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'
	from bin/rails:8:in `require'
	from bin/rails:8:in `<main>'

解決

ポートの問題を意識して、ポートの状況を確認します。

lsof -i:3000

何も出て来ないので、pumaの調べてみます。

ps aux | grep puma

=> root             35434   0.0  1.2  6327812 401596 s002  S    10:14AM   0:24.65 puma 3.12.1 (tcp://localhost:3000)


sudo kill -9 35434

これで解決。

結論

そもそも「Address already in use」という問題はポートが占有されていると認識すれば、その方向で調査進んでもらったら、解決ができます。
問題の想定と方向性の策定は大事と思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?