MyBB Community Forums

Full Version: multiple forums memcache bug
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I'll post this as a bug if you are using memcache and put two forums to the same memcache instance. Why you would do this? About the same reason why you might want to use one database for multiple cms in a domain.

If you have two forums in the same domain or even in different domains pointing to the same memcache server, they will access the same objects. This will affect you when setting up your forum and getting the forum data from the first forum and probably vice versa.

To replicate: Simply setup one forum in /forum1 set to use memcache. Go to "forums and posts" admin area and change categories and add two misc forums. On second forum set up in /forum2 to use memcache (same as first). If you try to access "forums and posts" you will see the listing of forum1.

Solution: allow a global key setting to separate the cache like the cookie setting(or just use that setting to prefix the objects).

Please document this in the config file for the next release. I am just testing mybb so I don't know what the existing behavior extends to beyond what i noticed.
Another solution would be to use the forum path as the global key. That should be unique.
(2009-08-17, 07:03 PM)labrocca Wrote: [ -> ]Another solution would be to use the forum path as the global key. That should be unique.

hmm...


// Set a unique identifier for all queries in case other forums are using the same memcache server
$this->unique_id = md5($mybb->settings['bburl']);
hrm. i wouldn't call this bogus. this behavior was observed in two domains with mybboard in a subdirectory of the same name pointed to the same memcache instance. Either way prepending objects is a good practice in cached objects but that's just me.
haha...hilarious
(2009-08-17, 08:39 PM)someguy Wrote: [ -> ]hrm. i wouldn't call this bogus. this behavior was observed in two domains with mybboard in a subdirectory of the same name pointed to the same memcache instance. Either way prepending objects is a good practice in cached objects but that's just me.

You can't have two forums in the same subdirectory.
sigh. I have stated two separate domains with a forum in a subdirectory of the same name. I hope you have at least tried to replicate the bug before stating it is bogus. However I am giving up on mybboard since it's not going to work on my configuration.
This bug is valid, I can reproduce it. It's a hen & egg problem; the memcache handler tries to generate a unique key based on $mybb->settings['bburl'], when actually that variable is not initialized at this point of execution.

init.php connects the cache, before it loads the settings (and the $mybb->settings = $settings part comes way later):

// Load cache
$cache->cache();

// Load Settings
if(file_exists(MYBB_ROOT."inc/settings.php"))
{
        require_once MYBB_ROOT."inc/settings.php";
}

This is a hen & egg problem, since loading the settings may also involve using the cache, but for using the cache you need the settings first...

Proposed fix:

in inc/cachehandlers/memchache.php find:

$this->unique_id = md5($mybb->settings['bburl']);

replace with:

if($config['memcache_unique_id'])
{
    $this->unique_id = $config['memcache_unique_id'];
}

else
{
    $this->unique_id = 'mybb';
}

in config*php add to the memcache sectionn:

$config['memcache_unique_id'] = 'mybb';

let the user configure this id as he configures memcache in the config.php
wow. thanks frostschutz for the validation. Once again programmers have become prey to over reliance on variables that are not explicitly set.
(2009-08-18, 03:32 PM)someguy Wrote: [ -> ]Once again programmers have become prey to over reliance on variables that are not explicitly set.
Enabling notice level warnings would pick these bugs up. Unfortunately, there's a lot of code which relies on it being disabled however... >_>
Pages: 1 2