Intermittent page loads in Ruby on Rails app

Hi Everyone, this one’s got me stumped.

I’ve got a ruby on rails site here (rails 2.0.2, ruby 1.8.6, running on
thins (0.8.2) sitting on top of nginx), and when I hit a certain action
I sometimes get the correct response, other times I get a 500 error.

The code in this view goes as follows:

def show
@item = Item.find_by_url_slug(params[:id])

filename = “#{RAILS_ROOT}/public/#{@item.index.url}”
@data = File.open(filename, ‘rb’) { |f| f.read } # read data via File.

render :layout => false
end

The view is rather simplistic, with show.html.erb containing

<%= @data %>

I’ve suspected caching, and have tried setting a variety of different
headers (cache-control, expires etc), and also tried the expires_now()
method, to no avail.

Out of interest I’ve also tried adding a sleep(2) call in the
controller, and looking at the network requests it’s obvious on the 500
pages that this method isn’t being called - none of the above code in
the show action is.

Furthermore, there’s no evidence of the call in the production.log when
the page doesnt load, or any errors in the nginx log. So, no errors to
debug, just the occasional 500 (happening say 2/4 page loads).

I should add that this code works fine locally, and on our staging
server - it’s only in production that this is an issue.

Any ideas??