Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

If your "key" is more than 255 characters, it sounds like you are doing something wrong. Why is your session key that long? What's wrong with MD5 or SHA1?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top