# CookieOverflow errors while using DB cookie store

**URL:** <https://www.ruby-forum.com/t/cookieoverflow-errors-while-using-db-cookie-store/155486>\
**Category:** Rails\
**Created:** [December 12, 2008, 8:49am UTC](https://www.ruby-forum.com/t/cookieoverflow-errors-while-using-db-cookie-store/155486 "2008-12-12T08:49:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![brady8](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecccb3/32.png) [@brady8](https://www.ruby-forum.com/u/brady8)\
**Post date:** [December 12, 2008, 8:49am UTC](https://www.ruby-forum.com/t/cookieoverflow-errors-while-using-db-cookie-store/155486/1 "2008-12-12T08:49:46Z")

</div>

Hello all,

Using Edge Rails, SQLite development database on OSX.  
I’m receiving CookieOverflow errors in my application while using the  
AR cookie store.  
Tested in both Safari and Firefox, same error, although sporadically  
(I can’t reliably reproduce the error in the same part of my  
application, seems to occur all over).  
The thing is, this is after clearing the browser cache in both Safari  
and FF, and Web D. addon for FF confirms that there isn’t  
even a session cookie being stored, just a 500 Failsafe error from  
Rails.  
Also, the obvious: tried stopping/starting the server multiple times,  
even wiped out the database and ran migrations from scratch.

The trace is below, but not very helpful. Has anyone else ran into a  
problem like this using the DB cookie store, and/or know how to fix  
it?

Thanks for your time,  
Brady  
removed\_email\_address@domain.invalid

Rails Trace: -------------  
Processing VoteController#index (for 127.0.0.1 at 2008-12-12 00:41:24)  
[GET]  
Parameters: {“action”=\>“index”, “controller”=\>“vote”, “key”=\>“2342”}

CGI::Session::CookieStore::CookieOverflow  
(CGI::Session::CookieStore::CookieOverflow):  
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/  
1.8/cgi/session.rb:324:in `close’

Rendered rescues/\_trace (93.7ms)  
Rendered rescues/\_request\_and\_response (6.3ms)  
Rendering rescues/layout.erb (internal\_server\_error)  
/!\ FAILSAFE /!\ December 12, 2008 12:41 AM  
Status: 500 Internal Server Error  
CGI::Session::CookieStore::CookieOverflow  
/Users/Crash/website/vendor/rails/actionpack/lib/action\_controller/  
session/cookie\_store.rb:111:in `close' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/1.8/cgi/session.rb:324:in`close’  
/Users/Crash/website/vendor/rails/actionpack/lib/action\_controller/  
base.rb:1300:in `close_session' /Users/Crash/website/vendor/rails/actionpack/lib/action_controller/ base.rb:1328:in`process\_cleanup\_without\_session\_management\_support’  
/Users/Crash/website/vendor/rails/actionpack/lib/action\_controller/  
session\_management.rb:137:in `process_cleanup' /Users/Crash/website/vendor/rails/actionpack/lib/action_controller/ base.rb:523:in`process\_without\_filters’  
/Users/Crash/website/vendor/rails/actionpack/lib/action\_controller/  
filters.rb:606:in `process_without_session_management_support' /Users/Crash/website/vendor/rails/actionpack/lib/action_controller/ session_management.rb:127:in`process’  
/Users/Crash/website/vendor/rails/actionpack/lib/action\_controller/  
rescue.rb:63:in `process_with_exception' /Users/Crash/website/vendor/rails/actionpack/lib/action_controller/ dispatcher.rb:131:in`failsafe\_rescue’  
/Users/Crash/website/vendor/rails/actionpack/lib/action\_controller/  
dispatcher.rb:65:in `dispatch_unlocked' /Users/Crash/website/vendor/rails/actionpack/lib/action_controller/ dispatcher.rb:76:in`dispatch’  
/Users/Crash/website/vendor/rails/actionpack/lib/action\_controller/  
dispatcher.rb:75:in `synchronize' /Users/Crash/website/vendor/rails/actionpack/lib/action_controller/ dispatcher.rb:75:in`dispatch’  
/Users/Crash/website/vendor/rails/actionpack/lib/action\_controller/  
dispatcher.rb:93:in `_call' /Users/Crash/website/vendor/rails/actionpack/lib/action_controller/ dispatcher.rb:57:in`initialize’  
/Users/Crash/website/vendor/rails/actionpack/lib/action\_controller/  
failsafe.rb:11:in `call' /Users/Crash/website/vendor/rails/actionpack/lib/action_controller/ failsafe.rb:11:in`call’  
/Users/Crash/website/vendor/rails/actionpack/lib/action\_controller/  
dispatcher.rb:87:in `call' /Users/Crash/website/vendor/rails/railties/lib/rails/rack/ static.rb:27:in`call’  
/Users/Crash/website/vendor/rails/railties/lib/rails/rack/  
logger.rb:14:in `call' /Library/Ruby/Gems/1.8/gems/rack-0.4.0/lib/rack/handler/mongrel.rb: 59:in`process’  
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in  
`process_client' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in`each’  
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in  
`process_client' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in`run’  
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in  
`initialize' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in`new’  
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in  
`run' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in`initialize’  
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in  
`new' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in`run’  
/Library/Ruby/Gems/1.8/gems/rack-0.4.0/lib/rack/handler/mongrel.rb:  
32:in `run' /Users/Crash/website/vendor/rails/railties/lib/commands/server.rb: 100 /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in`gem\_original\_require’  
/Library/Ruby/Site/1.8/rubygems/custom\_require.rb:31:in `require’  
script/server:3

---

<div class="post-metadata">

**Author:** ![brady8](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecccb3/32.png) [@brady8](https://www.ruby-forum.com/u/brady8)\
**Post date:** [December 12, 2008, 8:52am UTC](https://www.ruby-forum.com/t/cookieoverflow-errors-while-using-db-cookie-store/155486/2 "2008-12-12T08:52:45Z")

</div>

On 12 Dec 2008, at 07:49, brady8 wrote:

> Hello all,
> 
> Using Edge Rails, SQLite development database on OSX.  
> Are you trying to store lots of stuff in the session ?

Fred

---

<div class="post-metadata">

**Author:** ![brady8](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecccb3/32.png) [@brady8](https://www.ruby-forum.com/u/brady8)\
**Post date:** [December 12, 2008, 11:28am UTC](https://www.ruby-forum.com/t/cookieoverflow-errors-while-using-db-cookie-store/155486/3 "2008-12-12T11:28:57Z")

</div>

I am storing two small model instances in the session, but that  
shouldn’t be a problem since (as far as I know) there isn’t a data  
limit when storing sessions in the database.

Also, the problem happens even when the browser session is cleared, so  
no session exists yet, and (obviously) no data is stored in the  
session.

-Brady

On Dec 12, 12:52 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![brady8](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecccb3/32.png) [@brady8](https://www.ruby-forum.com/u/brady8)\
**Post date:** [December 12, 2008, 12:24pm UTC](https://www.ruby-forum.com/t/cookieoverflow-errors-while-using-db-cookie-store/155486/4 "2008-12-12T12:24:43Z")

</div>

On 12 Dec 2008, at 10:28, brady8 wrote:

> I am storing two small model instances in the session, but that  
> shouldn’t be a problem since (as far as I know) there isn’t a data  
> limit when storing sessions in the database.

They’re not being stored in the database. You’re using the cookie  
store which stores data in a cookie, which is limited to 4k (and since  
that data is base64 encoded that gives you roughly 3k tops)

> Also, the problem happens even when the browser session is cleared, so  
> no session exists yet, and (obviously) no data is stored in the  
> session.

The implication would be that on that first request you’re putting  
enough in the session to breach the limit

Fred

---

<div class="post-metadata">

**Author:** ![brady8](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecccb3/32.png) [@brady8](https://www.ruby-forum.com/u/brady8)\
**Post date:** [December 13, 2008, 5:49pm UTC](https://www.ruby-forum.com/t/cookieoverflow-errors-while-using-db-cookie-store/155486/5 "2008-12-13T17:49:56Z")

</div>

Thanks for the reply Fred!

Any idea then why it would switch to using the cookie store? Session  
data in general for the app is being stored/accessed from the database  
using AR.

From environment.rb:  
config.action\_controller.session = {  
:session\_key =\> ‘\_myapp\_session’,  
:secret =\> ‘’  
}  
config.action\_controller.session\_store = :active\_record\_store

From production.rb:  
config.action\_controller.session = { :session\_secure =\> true }  
config.action\_controller.session\_store = :active\_record\_store

The only session related code I have in this particular controller  
that seems to be giving me grief is this line:  
session :session\_secure =\> false, :if =\> Proc.new { |request| !  
request.ssl? }

This is so that cookies are marked as secure only if SSL is being used  
in the production environment, and I’m assuming this line would have  
no affect in development, which is where I’m running into this issue.

Any ideas?

-Brady

On Dec 12, 4:24 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
