Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I debug Unicorn that crashes with "undefined method `each' for nil:NilClass" as if the body returned from the app would be nil?
    text
    copied!<p>I'm running a Rails 3.2.13 app at Heroku with Unicorn, and I get seemingly randomly and very often (e.g. few times a minute) an unicorn error in my logs that tells the following, but not much else:</p> <pre><code>Jul 08 17:12:41 my_app app/web.1: E, [2013-07-08T14:12:41.153875 #21] ERROR -- : app error: undefined method `each' for nil:NilClass (NoMethodError) Jul 08 17:12:41 my_app app/web.1: E, [2013-07-08T14:12:41.157119 #21] ERROR -- : /app/vendor/bundle/ruby/1.9.1/gems/unicorn-4.6.3/lib/unicorn/http_response.rb:60:in `http_response_write' Jul 08 17:12:41 my_app app/web.1: E, [2013-07-08T14:12:41.157292 #21] ERROR -- : /app/vendor/bundle/ruby/1.9.1/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:562:in `process_client' Jul 08 17:12:41 my_app app/web.1: E, [2013-07-08T14:12:41.157367 #21] ERROR -- : /app/vendor/bundle/ruby/1.9.1/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:632:in `worker_loop' Jul 08 17:12:41 my_app app/web.1: E, [2013-07-08T14:12:41.157443 #21] ERROR -- : /app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.6.2.96/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb:22:in `call' Jul 08 17:12:41 my_app app/web.1: E, [2013-07-08T14:12:41.157523 #21] ERROR -- : /app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.6.2.96/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb:22:in `block (4 levels) in &lt;top (required)&gt;' Jul 08 17:12:41 my_app app/web.1: E, [2013-07-08T14:12:41.157600 #21] ERROR -- : /app/vendor/bundle/ruby/1.9.1/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:500:in `spawn_missing_workers' Jul 08 17:12:41 my_app app/web.1: E, [2013-07-08T14:12:41.157724 #21] ERROR -- : /app/vendor/bundle/ruby/1.9.1/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:142:in `start' Jul 08 17:12:41 my_app app/web.1: E, [2013-07-08T14:12:41.157802 #21] ERROR -- : /app/vendor/bundle/ruby/1.9.1/gems/unicorn-4.6.3/bin/unicorn:126:in `&lt;top (required)&gt;' Jul 08 17:12:41 my_app app/web.1: E, [2013-07-08T14:12:41.157870 #21] ERROR -- : /app/vendor/bundle/ruby/1.9.1/bin/unicorn:23:in `load' Jul 08 17:12:41 my_app app/web.1: E, [2013-07-08T14:12:41.158027 #21] ERROR -- : /app/vendor/bundle/ruby/1.9.1/bin/unicorn:23:in `&lt;main&gt;' </code></pre> <p>Investigating the Unicorn source a bit it seems that the body in the response that the app returns is nil, and that causes the crash. But I do not get any output from the app about this, and this seems to happen even when no requests are logged at all. I tried adding debug prints to rack middle ware but those do not get printed at all.</p> <p>I'm not very experienced with Unicorn and Rack so I'm asking for tips how to debug this further. </p> <p>While looking for similar questions online I found: <a href="http://jeffrafter.tumblr.com/post/8459308338/recalcitrant-unicorns" rel="nofollow">http://jeffrafter.tumblr.com/post/8459308338/recalcitrant-unicorns</a> which seems exactly similar situation. I tried the telnet approach with <code>heroku run</code> but it seems to say "Connection refused" at the port which is shown in the logs to be used by Unicorn. Are there other ways to get the real stack trace?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload