Problem/Motivation

DomainAliasHooks injects LoggerChannelFactoryInterface in its constructor. This creates a circular service dependency when any third-party logger module (jsonlog, raven, etc.) is enabled, because logger.factory is a service_collector that resolves ALL logger-tagged services during container compilation.

Error:

Circular reference detected for service "Drupal\Core\Logger\LoggerChannelFactoryInterface",
path: "plugin.cache_clearer -> plugin.manager.block -> logger.channel.default ->
Drupal\Core\Logger\LoggerChannelFactoryInterface -> logger.jsonlog ->
Drupal\domain_alias\Hook\DomainAliasHooks"

drush cr fails. drush updb works (different bootstrap path).

This is the same bug that was already fixed in #3549346 for DomainSourcePathProcessor, but DomainAliasHooks was missed.

Steps to reproduce

  1. Enable domain, domain_alias, and jsonlog (or raven) modules
  2. Run drush cr
  3. Circular reference error

Proposed resolution

Remove LoggerChannelFactoryInterface from DomainAliasHooks constructor and remove the two error log calls (lines 113 and 120).

This follows the same approach used in:

  • #3549346 — same bug in DomainSourcePathProcessor, already fixed by removing the logger dependency
  • Drupal core #2838474 — same pattern in FileSystem, removed logger dependency entirely

The logger was only used for two edge-case error messages when alias lookup fails (wrong domain ID, missing path prefix match). These conditions are still detectable by visible symptoms — wrong domain served, broken alias resolution.

Remaining tasks

Review and merge the MR.

User interface changes

None.

API changes

DomainAliasHooks::__construct() signature changes — LoggerChannelFactoryInterface parameter removed.

Data model changes

None.

Issue fork domain-3583279

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ugolek created an issue. See original summary.

mably made their first commit to this issue’s fork.

mably’s picture

Status: Active » Needs review

MR 354 introduces a lazy DomainLoggerFactory service in the domain module that wraps LoggerChannelFactoryInterface. Registered with lazy: true in domain.services.yml, its proxy is resolved only at runtime (when get() is called), not during container compilation — breaking the circular reference.

DomainAliasHooks now injects DomainLoggerFactoryInterface instead of LoggerChannelFactoryInterface. Other domain submodules can reuse this service to avoid the same circular dependency.

The first error log call (no prefix match) was removed as unreachable dead code. The second (orphaned alias pointing to a deleted domain) is kept via the lazy logger.

@ugolek Could you review and test MR 354 against your setup?

  • mably committed c0e3ad6e on 3.x
    fix: #3583279 Circular reference in DomainAliasHooks due to...
mably’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

mably’s picture

We merged the fix but wanted to note that we were unable to reproduce the circular reference locally (Drupal 11.3.5, PHP 8.5.3, jsonlog 4.1.0, domain_alias enabled).

Running drush cr with the code reverted to before the fix completed without error. The HookCollectorPass registers hook classes as standalone autowired services — it does not add them as dependencies of module_handler or any other service. So the intermediate chain from logger.jsonlog to DomainAliasHooks in the error path remains unclear to us.

We're keeping the fix since your stack trace seems valid and the lazy wrapper is harmless, but could you share your exact Drupal core version and PHP version? That would help us understand whether this is tied to a specific core version's container compilation behavior.

  • mably committed 9eb796eb on 3.x
    revert: #3583279 Circular reference in DomainAliasHooks due to...
mably’s picture

Status: Fixed » Closed (cannot reproduce)

Thanks again for reporting this issue.

I’ve pushed a change to revert the previous modifications, as I wasn’t able to reproduce the problem described on my side.

That said, opening an issue is only the first step — it’s also important to follow up and engage with any questions or requests for clarification from maintainers. Without that feedback loop, it’s difficult to investigate further or move things forward.