Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rack session key too long for memcached

I am running Rails 3 configured to use memcached for session store. I have the following setup:

development.rb

config.cache_store = :mem_cache_store

session_store.rb

Foo::Application.config.session_store :mem_cache_store, :key => '_foo_session'

I can start the app fine, when I go to any page I get the following error:

ArgumentError (key too long "rack:session:__really_long_session_key__"):

I realize the limit on memcached key is 255. How can I get around this, or am I doing something wrong?

like image 938
Jey Balachandran Avatar asked Sep 26 '10 22:09

Jey Balachandran


2 Answers

You're almost certainly seeing this because you're switching from the cookie store to memcached. Your browser still has the old session cookie, with the long ID. You need to delete this cookie from your browser and the problem will go away.

If you're switching from cookie store to memcached on a production site, this will be a problem because you don't have control over your user's browsers. You'll probably need to change the session key to avoid problems in this case.

like image 145
Steve Madsen Avatar answered Sep 29 '22 07:09

Steve Madsen


Is it possible you switched from the cookie store or you run other cookie session store apps on the same domain (e.g. localhost)?

In this case the cookie session store is responsible for the huge session_id string (because it actually stores the whole session in it). Just delete your session cookie and you are fine.

like image 25
jeanmartin Avatar answered Sep 29 '22 07:09

jeanmartin