Incomplete hook_info cached if there's an error/warning during module_load_all

Created on 22 March 2015, about 9 years ago
Updated 29 March 2023, about 1 year ago

I started seeing an error that was caused because the hook_info in bootstrap cache was missing data.

The problem is that if the hook_info cache is built/rebuilt before module_load_all (the method that loads all the .module files and direct module dependencies) has completed some modules will not get their hook_info's into the cache.

How can this happen?

In module_load_all:

function module_load_all($bootstrap = FALSE) {
  static $has_run = FALSE;

  if (isset($bootstrap)) {
    foreach (module_list(TRUE, $bootstrap) as $module) {
      drupal_load('module', $module);
    }
    // $has_run will be TRUE if $bootstrap is FALSE.
    $has_run = !$bootstrap;
  }
  return $has_run;
}

In my case, a warning was being issued inside drupal_load when loading one of the modules.

This is triggering the error handling system, that does a watchdog() call.

Inside watchdog():

    // Call the logging hooks to log/process the message
    foreach (module_implements('watchdog') as $module) {
      module_invoke($module, 'watchdog', $log_entry);
    }

Then module_invoke's inners is triggering the hook_info cache building (if not built already).

module_implements() is calling module_hook_info() to see if the watchdog hook has been implemented by any module, and if the hook_info cache is not built, the following code that is building the hook_info cache will not take into account modules that have not yet been through drupal_load:

foreach (module_list() as $module) {
        $function = $module . '_hook_info';
        if (function_exists($function)) {
          $result = $function();
          if (isset($result) && is_array($result)) {
            $hook_info = array_merge_recursive($hook_info, $result);
          }
        }
      }

Of course no warning should be issued during module_load_all() but if that happens, this needs to be more robust. And maybe watchdog should be one of the first modules in the module_load_all().

Needs some more investigation.

🐛 Bug report
Status

Active

Version

7.0 ⚰️

Component
Bootstrap 

Last updated 9 days ago

No maintainer
Created by

🇪🇸Spain david_garcia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024