PDA

View Full Version : Problem with Memcache / forking


jerrett
05-13-2009, 12:30 PM
http://www.modrails.com/documentation/Users%20guide.html#_example_1_memcached_connection _sharing_harmful


I'm running into a similar problem with Litespeed... Memcache is returning incorrect objects, sometimes.

Any ideas of a solution? How would one go about reseting the connection to memcache each time it's forked, if this is the problem?

jerrett
05-13-2009, 01:07 PM
This also just started happening with the new Litespeed and Rails 2.3 (Rack)..

mistwang
05-13-2009, 01:37 PM
Yes, need to reset the connection to memcache. Just close all connections after the initialization.

jerrett
05-13-2009, 01:42 PM
Would it be a good place to do this in environment.rb, or is that not going to get executed when it's forked?

mistwang
05-13-2009, 01:47 PM
It should be fine. environment.rb only get loaded once I think.

jerrett
05-13-2009, 02:01 PM
Doesn't seem to help, if it's only loaded once i'm assuming that means it won't reset when the process gets forked.. where would we hook into that?

mistwang
05-13-2009, 02:23 PM
maybe it is too early as the connection to memcache was established after loading environment.rb.

Please try to patch RailsRunner.rb, at where "ActiveRecord::Base.clear_active_connections!" is called.

jerrett
05-13-2009, 06:45 PM
It worked, but we had to manually create a cache object for the session store so we could call reset on it (and then just SESSION_CACHE.reset right before the clear_active_connections!)

In the edge of rails it looks like there is a way to access the Session memcache instance, which would mean it could in the future be fixed in RailsRunner.rb by default.. something to look forward to perhaps :)

mistwang
05-13-2009, 08:18 PM
Yes, please keep us posted when it is available, so we can add som generic code like "clear_active_connections!" to address it in RailsRunner.rb .