Angular manager module caching issue (TypeError in_array)
Related question was raised here: https://civicrm.stackexchange.com/questions/46379/typeerror-in-array-angular-managerresolvedefaultmodules-civicrm-version-5
I think this is a recent change which might have caused the issues (or highlighted them): https://github.com/civicrm/civicrm-core/commit/604cca726c6a238e0530b5f660ab0e11596da090#diff-b26b657986ef8b8163e79bcaf85afe628f6d5457193253bc6ff4c009cca44bf5
We're seeing an intermittent issue where pages fail to load with a fatal error. The only path we've detected it on is /civicrm/transact .
It's caused by \Civi\Angular\Manager::resolveDefaultModules
looking for the 'basePages' array for a module definition, but it's not there. After some checking, it looks like the value is just null (ie, there's no definition set).
Digging back through \Civi\Angular\Manager::getModules we can see that this checks to see if $this->cache->get('moduleNames');
is null. If it is, it rebuilds the list of modules and saves it to the cache, and then goes through each module and saves the definition to the cache - using separate cache key entries (I guess because otherwise the cache entry would be too big?)
$angularModules = $this->resolvePatterns($angularModules);
$this->cache->set('moduleNames', array_keys($angularModules));
foreach ($angularModules as $moduleName => $moduleInfo) {
$this->cache->set("module $moduleName", $moduleInfo);
}
If moduleNames
is already set, then it rehydrates the data from the cache:
// Rehydrate modules from cache
else {
foreach ($moduleNames as $moduleName) {
$angularModules[$moduleName] = $this->cache->get("module $moduleName");
}
The problem I think we're seeing intermittently is that $this->cache->get('moduleNames');
is set but the individual module definitions (or some of them at least) are not set $this->cache->get("module $moduleName");
. This means the value is set as 'NULL', which is causing the original error.
I'm struggling to find the exact steps to recreate this issue, but I think the related code could do with tightening up in either case?
It doesn't look like we can rely on the 'module ...' cache entries being set if the 'moduleNames' entry is set?
Ping @colemanw