Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento "Front controller reached 100 router match iterations" error

My site is going down once or twice a day when it starts throwing the exception "Front controller reached 100 router match iterations". Once this happens access to the admin and frontend is gone. I am just left with an error page.

This started after upgrading from Magento 1.5.0.1 to 1.5.1.0. If I manually clear the var/cache/ directory I am up and running again.

I have googled the heck out of this one. In the limited search results I have found nothing has helped me with resolving this.

Any insight into why this may be happening and how it could be resolved would be appreciated.

--update-----------------------

Using the debugging code provided in the helpful answer from, Andrey Tserkus, I was able to determine that the error is caused by some of my routers disappearing.

The normal routers output by the debug code are: Total 7: admin, standard, cms, amshopby, fishpig_wordpress, seosuite, default

When the error occurs they have changed to: Total 3: admin, standard, default

When this happens it seems the missing routes causes the code to iterate to 100 for every page request. I will investigate this condition further.

like image 315
Christian Avatar asked Jun 07 '11 07:06

Christian


4 Answers

UPDATE 2: I have some further changes which should help prevent a different cause of the 100 router match iterations

https://github.com/convenient/magento-ce-ee-config-corruption-bug#update-2-further-improvements

====================================================================

UPDATE: MAGENTO HAVE USED MY ANSWER AS A PATCH

https://github.com/convenient/magento-ce-ee-config-corruption-bug#update-good-news-a-patch-from-magento

====================================================================

I've recently spent quite some time looking into this bug. I've written up my full findings, explanation and replication here.

https://github.com/convenient/magento-ce-ee-config-corruption-bug

However, for the short answer. This appears to be a Magento bug which can be corrected by overriding Mage_Core_Model_Config::init with the following:

 public function init($options=array())
 {
     $this->setCacheChecksum(null);
     $this->_cacheLoadedSections = array();
     $this->setOptions($options);
     $this->loadBase();

     $cacheLoad = $this->loadModulesCache();
     if ($cacheLoad) {
         return $this;
     }
     //100 Router Fix Start
     $this->_useCache = false;
     //100 Router Fix End
     $this->loadModules();
     $this->loadDb();
     $this->saveCache();
     return $this;
 }

EDIT: Updated to test on vanilla 1.5

I just ran the replication script on a vanilla install of 1.5. Which had all caches except for the CONFIG cache disabled.

It did not produce the 100 router error as it does on 1.13, but it did break the website and all the homepage displayed was a white screen.

The cause was that when we were looking for a controller and action we were matched with Mage_Core_IndexController::indexAction instead of Mage_Cms_IndexController::indexAction.

class Mage_Core_IndexController extends Mage_Core_Controller_Front_Action {

    function indexAction()
    {

    }
}

Mage_Core_IndexController::indexAction is an empty function, and explains the white page perfectly.

I can no longer replicate this error when placing _useCache = false into Mage_Core_Model_Config.

I believe that maybe your Magento sites unique configuration might cause it to completely fail to match a controller, as opposed to falling back to this Mage_Core_IndexController action?

like image 131
Luke Rodgers Avatar answered Nov 13 '22 23:11

Luke Rodgers


The error message is too general to try to solve this problem. I suggest you to hire some freelancer Magento web-developer to look to the source of the problem on your actual site. It cannot be solved theoretically.

As seen from the message, the problem occurs because your routers are making circular references for dispatching requests. One of them matches request, but doesn't dispatch and pushes it to redispatch again. Or no router matches request at all.

You can get more information by going to Magento Core file app/code/core/Mage/Core/Controller/Varien/Front.php, find there lines

while (!$request->isDispatched() && $i++<100) {
    foreach ($this->_routers as $router) {
        if ($router->match($this->getRequest())) {
            break;
        }
    }
}

and replace them with

Mage::log('----Matching routers------------------------------');
Mage::log('Total ' . count($this->_routers) . ': ' . implode(', ', array_keys($this->_routers)));
while (!$request->isDispatched() && $i++<100) {
    Mage::log('- Iteration ' . $i);
    $requestData = array(
        'path_info' => $request->getPathInfo(),
        'module' => $request->getModuleName(),
        'action' => $request->getActionName(),
        'controller' => $request->getControllerName(),
        'controller_module' => $request->getControllerModule(),
        'route' => $request->getRouteName()
    );

    $st = '';
    foreach ($requestData as $key => $val) {
        $st .= "[{$key}={$val}]";
    }
    Mage::log('Request: ' . $st);
    foreach ($this->_routers as $name => $router) {
        if ($router->match($this->getRequest())) {
            Mage::log('Matched by "' . $name . '" router, class ' . get_class($router));
            break;
        }
    }
}

After that wait for site to produce the error, open var/log/system.log and see there debugging information about what is going on inside your system. It will help to see much more better, what router breaks the system.

like image 30
Andrey Tserkus Avatar answered Nov 14 '22 01:11

Andrey Tserkus


This message is caused by bad cached config data. I'm not sure what actually causes the cached config to become corrupted - I would guess it could be a number of things that would vary depending on how Magento is running.

I guess, if you can still get to the Magento backend, you can trying clearing cache under System > Cache Management. If that doesn't help (or if you can't get to the Magento backend, which is likely with this error), then determine how your caching is set up by finding the value of < cache >< backend > in app/etc/local.xml. If you're using files for cache (the default), can you can clear out magento/var/cache with

rm -rf /path/to/magento/var/cache/*

If you're using memcached, find the port under < port > and you can do

telnet memcache_server portnumber
flush_all

Or if you're using redis, you can do

telnet redis_server portnumber
FLUSHALL
like image 28
siliconrockstar Avatar answered Nov 13 '22 23:11

siliconrockstar


We've been having the same issue, and dug a little deeper to discover that the issue doesn't directly relate to which routers are loaded but which modules are loaded.

To work this out we added the following debug code:

    app/code/core/Mage/Core/Controller/Varien/Front.php : Line 183

    if ($i>100) {
        file_put_contents('/tmp/debug.txt', Mage::getConfig()->getNode()->asNiceXml());
        Mage::throwException('Front controller reached 100 router match iterations');
    }

When we check the output of this, we can see that ONLY the Mage_Core module is loaded (check the node 'config/modules'. We think there is some kind of race condition that is occuring that means the system is left with a partially formed config that is then cached.

Would be interested in hearing if you have the same situation.

like image 44
Peter O'Callaghan Avatar answered Nov 14 '22 01:11

Peter O'Callaghan