views:

363

answers:

3

Suddenly, in my first Rails app, I've started seeing this error:

/!\ FAILSAFE /!\  Fri Sep 11 17:30:48 -0400 2009
Status: 500 Internal Server Error
ActionController::Session::CookieStore::CookieOverflow

A little research points to the usage of of cookies to store session data, but I'm not doing that (at least not intentionally). Moreover, this just started happening today. The only thing I've started working on today is the ability to upload a zip file. The zip file that I'm trying to use for testing is 1.1MB.

Additionally, Firebug shows only 2 cookies for this domain. The one named _html_session is 507B and the one named user_credentials is 147B. Are uploaded files temporarily stored in such a way that a large-ish file could be causing this? Uploading a single image works just fine.

Thanks for your help.

UPDATE: Oops. Contrary to my comments to Vitaly and xijo below, the error is not quite instant. In this case I'm uploading something to my Image model and the error is happening when my ImagesController calls @image.save!.

What's interesting is that I still don't really understand where the error happens. I created an Image#before_validation method and raising an exception there, but the CookieOverflow error happens before I ever get there. Is there any place I can drop code after the controller makes the save call and before that particular callback? My understanding is that before_validation is the first callback.

A: 

Hello Rob,

no, temporarily uploaded files are usually stored in your temp folder and have nothing to do with the cookie and its size.

What do you store in your session object and perhaps it is really a good idea to start storing the session object in the database if you use it permanently.

Joe
Damn, since that's the only (significant) thing I can think of that I changed, I was hoping that was the problem. Suggestion to move session storage to the database noted, but I'd like to figure out what's happening here before I do that. Appreciate the response.
Rob Wilkerson
Did you do some output like session.inspect to see what data is written to it during your requests? Does it occure after a number of requests or instantly?
Joe
It's definitely instant. As I just commented to Vitaly's answer, I never even seem to arrive at the `create` method of my controller. I do have my cookies listed, but there's only 2 and the sizes total less than 1MB (assuming Firebug reporting is sufficient).
Rob Wilkerson
Oops. Inadvertent lie. It's not quite instant. I've updated the original question with what I'm seeing.
Rob Wilkerson
A: 

the only thing that comes to mind is that you somehow did put your .zip into the session.

To debug it:

  • add 'require "ruby-debug"' to your environment.rb
  • find the place where it prints the error message and put a 'debugger' there.
  • run it and it will stop when it hits the 'debugger' command
  • examine the call stack to see if there is anything relevant.
  • examine the session at that point in time. see what exactly takes the space there.
Vitaly Kushner
The thing is, it errors out before it even gets to the `create` method of the controller. No code is ever executed, as far as I can tell.
Rob Wilkerson
Oops. Inadvertent lie. It's not quite instant. I've updated the original question with what I'm seeing.
Rob Wilkerson
+2  A: 

Hi Rob,

I just ran into a similar problem today. Apparently, Rails sessions can only store 4k of data. One possible solution it to use a database store for your sessions.

To do this:

  1. Add config.action_controller.session_store = :active_record_store to your environment.rb file.
  2. Create a migration file for your sessions using rake db:sessions:create
  3. Run the migration rake db:migrate

Hope this helps

Buzzy
Thanks. Buzzy. In my case, I wasn't even writing to the session (at least not intentionally), so that was the cause for my confusion.
Rob Wilkerson