views:

86

answers:

1

I am getting this error in maybe one out of 50-100 requests. I am running 10 Thin instances behind nginx and I don't think that my load is high enough to max out the usage in all 10 instances.. and I would expect nginx to wait even if all instances were busy (maybe not??). Has anyone else seen this before? I am trying to figure out a good way to debug it.

Here is my setup: CentOS 5.5 on Rackspace Cloud Servers 2GB instance nginx 0.7.67 Thin 1.2.7 Rails 3RC Ruby 1.9.2rc2

Nginx and 10 Thin instances are running on the same server.

+1  A: 

caches_action plus a redirect_to inside the action was causing this. It appears that it was writing to the cache (or possibly reading from) and then redirecting which caused the connection to close prematurely. I was able to get around the issue by using the if condition in caches_action to detect whether the redirect was going to occur. If I detected that it was going to occur, I returned false in x.cacheable?

my_controller.rb

caches_action :show, :if => Proc.new { |x| x.cacheable? }

action_controller.rb

def cacheable?
  params[:id]>1000 ? true : false
end

Basically, I needed to redirect_to another controller if params[:id]<1000, so the cacheable? def checks this and tells caches_action not to cache in this particular situation.

cowboycoded