2014-08-31 130 views
3

我遇到了一個真正的大問題。我的應用程序正在做幾千個SQL查詢,然後突然出現這個錯誤。如果我通過rake任務或rails控制檯直接執行我的代碼,這沒有什麼不同。SystemStackError:堆棧級別太深 - sql.active_record?

有誰知道這意味着什麼?從來沒有見過與軌道記錄器有關的這個錯誤。

ENV:
紅寶石2.1.2
的Postgres 9.3
軌4.1.5

Could not log "sql.active_record" event. SystemStackError: stack level too deep ["/Users /ghostrifle/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.5/lib/active_support/tagged_logging.rb:46"] 
SystemStackError: stack level too deep 
from /Users/ghostrifle/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/workspace.rb:86 
Maybe IRB bug! 

後23個呼叫者異常升高。

這裏的檢查SystemStackError例外

[ 
    "/Users/ghostrifle/Entwicklung/xxx_main/lib/tasks/tree_spot.rake:42:in `block (2 levels) in <top (required)>'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:240:in `call'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:240:in `block in execute'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:235:in `each'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:235:in `execute'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'", 
    "/Users/ghostrifle/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:172:in `invoke_with_call_chain'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:165:in `invoke'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:150:in `invoke_task'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:106:in `each'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:106:in `block in top_level'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:115:in `run_with_threads'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:100:in `top_level'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:78:in `block in run'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/bin/rake:33:in `<top (required)>'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/bin/rake:23:in `load'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/bin/rake:23:in `<main>'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'", 
    "/Users/ghostrifle/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'" 
] 
+0

當這種情況開始發生時,會發生什麼特別的事情?你有沒有檢查你的代碼沒有無窮遞歸?看看這個http://dalibornasevic.com/posts/5-ruby-stack-level-too-deep-systemstackerror – dabadaba 2014-08-31 22:19:05

+0

thnx的鏈接,我現在試着ulimit命令 – ghostrifle 2014-08-31 22:21:50

+0

以及..我的堆棧大小是8192巨大..但即使通過「ulimit -s 16384」增加它並沒有幫助。同樣的錯誤,仍然有23個調用者 – ghostrifle 2014-08-31 22:25:12

回答

0

的可否請你展示這是造成這個問題的代碼。根據我的理解,您正在保存一個堆棧,您正在添加從數據庫中獲取的數據,但可能您沒有將其初始化爲[]。因此,每次運行代碼時,數據都會堆積並最終導致此問題。

+1

可能是你做了一些無限循環,比如如果你在before_update裏面調用update_attributes,它會創建一個無限循環,同樣的錯誤會被拋出'棧層太深'。你可以弄明白。查看你的代碼。 – abhsss96 2014-10-10 17:56:10

相關問題