Circular reference detected for service "hook_event_dispatcher.module_handler"

Created on 15 November 2023, over 1 year ago

Problem/Motivation

I see the error while running any Drush command:

Circular reference detected for service "hook_event_dispatcher.module_handler", path: "hook_event_dispatcher.module_handler -> hook_event_dispatcher.manager -> event_dispatcher -> tracer.tracer -> tracer.tracer_
factory -> plugin.manager.tracer".

Drupal 10.1.2

I can't run any Drush command anymore

Steps to reproduce

In my I enabled hook_event_dispacther, core_event_dispatcher. Created custom EventSubscriber with using EntityHookEvents::ENTITY_VIEW => 'entityViewCallback' in getSubscribedEvents() function

๐Ÿ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States bob.hinrichs

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

Merge Requests

Comments & Activities

  • Issue created by @bob.hinrichs
  • ๐Ÿ‡ช๐Ÿ‡ชEstonia mikkmiggur

    We got the same issue from today.
    Getting it after drush cr command.
    If I do drush cim then 1 time it's clean and I can run any command.
    After that, I'm getting again this error.

    The only solution at the moment is to uninstall webprofiler and tracer.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly lussoluca Italy

    mikkmiggur are you using the hook_event_dispacther module as bob.hinrichs ?

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands cleverhoods

    There's a hotfix patch that would circumvent the error: https://www.drupal.org/project/hook_event_dispatcher/issues/3385203#comm... ๐Ÿ› Circular reference detected for service "hook_event_dispatcher.module_handler" Active

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Robin.Houtevelts

    After applying the patch above I was still seeing this error.
    In my case I was using drupal/office_hours โ†’ which seems to call the ModuleHandler very very early in their .module file.

    I fixed it by replacing those two lines with:

    require_once __DIR__ . '/office_hours.theme.inc';
    require_once __DIR__ . '/office_hours.theme.exceptions.inc';
    

    Leaving it here in case it might help someone else.

  • Pipeline finished with Skipped
    12 months ago
    #143655
  • Status changed to Fixed 12 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly lussoluca Italy
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States bob.hinrichs

    This problem has resurfaced for us:

    hook_event_dispatcher: 4.2.0
    tracer: 1.0.4
    drupal core: 10.4.5
    We are running lando with a pantheon recipe (if that matters).

    When hook_event_dispatcher and tracer are enabled, and one runs drush updb, the following error results:

    Circular reference detected for service "hook_event_dispatcher.module_handler", path: "hook_event_dispatcher.module_handler -> hook_event_dispatcher.manager -> hook_event_dispatcher.module_handler".

    Some guesses as to why this is:

    This error occurs during updb, because it has a special bootstrap mode that ensures all modules are loaded and update hooks are discovered in a single run, so it is instantiating the whole thing at once, and bringing the circular reference to light. Whereas in a normal page request, some services are only loaded on demand.

    Tracerโ€™s services include:

    plugin.manager.tracer:
    class: Drupal\tracer\TracerPluginManager
    parent: default_plugin_manager

    TracerPluginManager extends Drupalโ€™s DefaultPluginManager. That core base class automatically loads the module_handler. If you then have a circular dependency from module_handler โ†’ hook_event_dispatcher.manager โ†’ module_handler, enabling Tracer is the catalyst that triggers it during drush updb. \Drupal\tracer\TracerPluginManager extends DefaultPluginManager and calls parent::__construct. This parent class requires module_handler.

    I will add an issue for tracer and cross-reference this, since I don't have enough understanding to know where the fix would reside, if a fix is possible.

    Curious to see if this is reproducible by others.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States bob.hinrichs
Production build 0.71.5 2024