LoginSignup
4
2

More than 3 years have passed since last update.

Rails で SystemStackError stack level too deep の解決

Posted at

環境

ruby 2.5.3
rails 5.1.7

エラー

作成中のアプリのブラウザで投稿一覧画面に移動した時、ページが読み込まれない
サーバー画面を見てみると、

SystemStackError stack level too deep

の文字が。
そして、

app/controllers/posts_controller.rb:52:in `request'

が何行もある。

解決法

 サーバーを停止

ctrl+cやターミナルを消してもサーバーが停止しなかったため、以下の方法を使った。

$ lsof -i:3000
COMMAND     PID       USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
com.apple   687 hoge  131u  IPv6 0xa83beccf9a6cd3c1      0t0  TCP localhost:64379->localhost:hbci (ESTABLISHED)
ruby      64604 hoge   11u  IPv4 0xa83beccf991edd81      0t0  TCP localhost:hbci (LISTEN)
ruby      64604 hoge   21u  IPv6 0xa83beccf9964eac1      0t0  TCP localhost:hbci (LISTEN)
ruby      64604 hoge   26u  IPv6 0xa83beccf9a6cfc01      0t0  TCP localhost:hbci->localhost:64378 (CLOSE_WAIT)

でlocalhost:3000のプロセスを取得

$ kill -9 64604

で停止、もう一度

$ lsof -i:3000

で何も出ないことを確認。

$ rails s

無事サーバーが立ち上がった。

根本的な原因

ここに書いてある通り、アクション名にrequestを使うと、予約語のrequestを上書きしてしまい、無限ループになってしまうようだ。
→アクション名を変更して無事解決。

4
2
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
4
2