http_response seems to be using String.each

Eric Wong normalperson at yhbt.net
Wed Sep 21 20:46:13 EDT 2011


Joe Marty <joe at ownlocal.com> wrote:
> I just installed Unicorn 4.1.1 to serve a Rails 3 project behind nginx
> on a server running Ruby 1.9.2 and I'm getting this error on every app
> request:
> 
> app error: undefined method `each' for #<String:0xc42712c> (NoMethodError)
> /usr/local/lib/ruby/gems/1.9.1/gems/unicorn-4.1.1/lib/unicorn/http_response.rb:41:in
> `http_response_write'

I suspect you have some buggy middleware that's returning Strings
as the body (instead of Strings inside Arrays or something else)

What middlewares do you have loaded?

You can insert Rack::Lint in between every middleware to detect buggy
ones.  If Rack::Lint slows you down too much, you can also try just
removing them one-at-a-time to isolate the buggy one.

> I don't know for sure if 'body' is supposed to be an array, or if it's
> correctly a string and Unicorn is actually trying to read the string 1
> line at a time using the each method, which was changed in ruby 1.9 to
> 'String.each_line'.  Any ideas?

The Rack spec only requires the response body respond to the "each"
method and that yields String (or String-like) objects.

> The rails app does work fine in Passenger, and if I just swap out
> passenger for Unicorn, it fails with that message.

Maybe Passenger is more lenient with the Rack specs and/or working
around bugs.

-- 
Eric Wong


More information about the mongrel-unicorn mailing list