mehulkar
mehulkar

Reputation: 4974

Nginx/Passenger/Rails "upstream prematurely closed connection while reading response header from upstream"

I made a small change to my Rails 4 application where I set response.headers in a before_action on ApplicationController:

class ApplicationController < ActionController::Base
  before_action :set_response_headers

  def set_response_headers
    response.headers['FOO'] = some_object.id if some_object
    response.headers['ABC'] = other_object.id if other_object
  end
end

Nginx error logs say:

2015/01/20 09:49:34 [error] 3401#0: *504273 upstream prematurely closed connection while reading response header from upstream, client: xx.xx.xx.xx, server: localhost, request: "GET /api/v1/foos HTTP/1.1", upstream: "passenger:/tmp/passenger.1.0.3380/generation-0/request:", host: "foo.com"

When I make the request to /api/v1/foos, I see the request hitting Rails and logs seem to progress as normal, but the response craps out.

I don't see many resolved issues on here or around Google with this specific issue, and I'm also not sure that this isn't a PEBCAK issue.

Upvotes: 0

Views: 1924

Answers (1)

raykin
raykin

Reputation: 1757

Try this

response.headers['FOO'] = some_object.id.to_s if some_object
response.headers['ABC'] = other_object.id.to_s if other_object

Passenger require header value to be string or array

Upvotes: 1

Related Questions