New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in Rack when using halt with page cache #973

Closed
jasonseney opened this Issue Dec 24, 2012 · 4 comments

Comments

Projects
None yet
4 participants
@jasonseney

jasonseney commented Dec 24, 2012

I'm receiving the following error on every other page request when calling halt (with any response code).

ERROR NoMethodError: undefined method `each' for 404:Fixnum
/Users/jasonseney/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/handler/webrick.rb:71:in `service'
/Users/jasonseney/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/Users/jasonseney/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/Users/jasonseney/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

Version: 0.10.7

Steps to Reproduce:

  • padrino g project test_app
  • Add the following in app.rb:

register Padrino::Cache
enable :caching
set :cache, Padrino::Cache::Store::Memory.new(50)
get '/', :cache => true  do
    halt 404
end
@dariocravero

This comment has been minimized.

Show comment
Hide comment
@dariocravero

dariocravero Dec 27, 2012

Contributor

I can verify that it happens when the cached value is being retrieved and if you're returning a number or the result of halt 404 which ends up being a Fixnum after its cached.

However that's a half truth because your cached answer there is actually a 200 response! What happens is that Padrino's cache gets the 404 Fixnum and sends it to Sinatra to be served as a 200 response with its body's content set to 404 but the Fixnum not a String. So the caching mechanism might be failing to cache the status code, although I don't know if that's its responsibility or not.

If you want to see this working a bit further, try changing Sinatra's body implementation for @body = Fixnum === value || String === value ? [value.to_s] : value.

@DAddYE @achiu @joshbuddy is this a bug? Can you can clarify this better? :) Hope I didn't make too much of a mess with the explanation @jasonseney!

Contributor

dariocravero commented Dec 27, 2012

I can verify that it happens when the cached value is being retrieved and if you're returning a number or the result of halt 404 which ends up being a Fixnum after its cached.

However that's a half truth because your cached answer there is actually a 200 response! What happens is that Padrino's cache gets the 404 Fixnum and sends it to Sinatra to be served as a 200 response with its body's content set to 404 but the Fixnum not a String. So the caching mechanism might be failing to cache the status code, although I don't know if that's its responsibility or not.

If you want to see this working a bit further, try changing Sinatra's body implementation for @body = Fixnum === value || String === value ? [value.to_s] : value.

@DAddYE @achiu @joshbuddy is this a bug? Can you can clarify this better? :) Hope I didn't make too much of a mess with the explanation @jasonseney!

@ujifgc ujifgc closed this in 8dc17e2 Jan 11, 2013

skade added a commit that referenced this issue Jan 11, 2013

Merge pull request #1000 from ujifgc/fix-cache
Fix #973, refuse to cache integer statuses, test
@dariocravero

This comment has been minimized.

Show comment
Hide comment
@dariocravero

dariocravero Jan 12, 2013

Contributor

Thanks a million @ujifgc!!! :)

Contributor

dariocravero commented Jan 12, 2013

Thanks a million @ujifgc!!! :)

@ramesh2007

This comment has been minimized.

Show comment
Hide comment
@ramesh2007

ramesh2007 Apr 6, 2013

NoMethodError at /
undefined method `entries' for 404:Fixnum

file: index.erb
location: block in singletonclass
line: 199

ramesh2007 commented Apr 6, 2013

NoMethodError at /
undefined method `entries' for 404:Fixnum

file: index.erb
location: block in singletonclass
line: 199
@dariocravero

This comment has been minimized.

Show comment
Hide comment
@dariocravero

dariocravero Apr 8, 2013

Contributor

Can you elaborate on how to reproduce that error @RatnamRaju? Thanks!

Contributor

dariocravero commented Apr 8, 2013

Can you elaborate on how to reproduce that error @RatnamRaju? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment