Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Issue 70 - Make Rack::Cache multithread friendly #71

Merged
merged 1 commit into from

4 participants

@jtblin

As described in #70, this will fix the issue with asstes not being loaded correctly when using puma, a multithreaded ruby app server. This changes /lib/rack/cache/context.rb call method from

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

to

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

Let me know what you think.

@rtomayko
Owner

Seems sane enough. Why would rack.run_once be set in that case though?

@rtomayko
Owner

Sorry, I missed the description in #70. It still seems really wrong that puma would set run_once true but I guess we'll go with it. The run_once path is mostly there for tests. This should be fine.

@rtomayko rtomayko merged commit 5f0ce14 into from
@rtomayko rtomayko referenced this pull request in puma/puma
Closed

Loading Incorrect Images #57

@jtblin

Yes you're correct that puma should not set rack.run_once to true, they will actually change that in 1.0.7 but it doesn't hurt to test for rack.multithread anyways. Thanks for accepting the pull request!

@Gibheer

Hi,

can you please do a release with that fix? I also hit this bug and search two days for a solution.

thank you

@adrianmacneil

:+1: please publish a gem version with this patch included

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 4, 2012
  1. @jtblin
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 1 deletion.
  1. +1 −1  lib/rack/cache/context.rb
  2. +1 −0  test/spec_setup.rb
View
2  lib/rack/cache/context.rb
@@ -45,7 +45,7 @@ def entitystore
# each request in a dup object unless the +rack.run_once+ variable is
# set in the environment.
def call(env)
- if env['rack.run_once']
+ if env['rack.run_once'] && !env['rack.multithread']
call! env
else
clone.call! env
View
1  test/spec_setup.rb
@@ -149,6 +149,7 @@ def cache_config(&block)
def request(method, uri='/', opts={})
opts = {
'rack.run_once' => true,
+ 'rack.multithread' => false,
'rack.errors' => @errors,
'rack-cache.storage' => @storage
}.merge(opts)
Something went wrong with that request. Please try again.