Skip to content

Loading…

Rack::Cache is not multithread friendly #70

Open
jtblin opened this Issue · 0 comments

1 participant

@jtblin

When using puma with Rack::Cache, the assets do not get loaded correctly, this issue is described on the puma project: puma/puma#57

I found out that puma sets env['rack.run_once'] to true and rack-cache uses this information to determine to run the request on a non threadsafe mode, i.e. in /lib/rack/cache/context.rb:48.

def call(env)
  if env['rack.run_once'] 
    call! env
  else
    clone.call! env
  end
end

As per rack specs (http://rack.rubyforge.org/doc/files/SPEC.html), rack.run_once is not a guaranty that the application will be served only once. The specs also describe rack.multithread if the application object may be simultaneously invoked by another thread in the same process. I'll send a pull request to add test that rack.multithread is not set to true i.e.

def call(env)
  if env['rack.run_once'] && !env['rack.multithread']
    call! env
  else
    clone.call! env
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.