Problem/Motivation

On Drupal 11.3 with Commerce 3.3.6, the service container fails with a circular reference whenever the logger factory is touched during bootstrap:

Circular reference detected for service "Drupal\Core\Logger\LoggerChannelFactoryInterface", path:                                                                                                                                                                            
    "acquia_connector.subscription                                                                                                                                                                                                                                                        
     → acquia_connector.client.factory                                                                                                                                                                                                                                                    
     → Drupal\Core\Logger\LoggerChannelFactoryInterface                                                                                                                                                                                                                                   
     → Drupal\commerce\Hook\CommerceHooks      
     → commerce.inbox_message_fetcher                                                                                                                                                                                                                                                     
     → commerce.logger                                                                                                                                                                                                                                                                    
     → Drupal\Core\Logger\LoggerChannelFactoryInterface".                                                                                                                                                                                                                                 
  

This blocks drush updatedb, drush cr, and any HTTP request. The cycle exists because:

  • D11's OOP #[Hook] system instantiates hook services as soon as the logger factory is initialised.
  • Drupal\commerce\Hook\CommerceHooks::__construct() directly injects InboxMessageFetcherInterface.
  • InboxMessageFetcher directly injects commerce.logger, which is a factory call back to logger.factory (LoggerChannelFactoryInterface).

This is the same class of cycle that was fixed by #3587604 for commerce_cart and commerce_order (using #[AutowireServiceClosure]) — but the same fix was never applied to
CommerceHooks in the base commerce module.

Steps to reproduce

  1. Install a Drupal 11.3.x site with Drupal Commerce 3.3.6 and drupal/acquia_connector (or any module that depends on the logger factory at boot).
  2. Run drush updatedb:status or drush cr.
  3. Container compilation fails with the circular reference error above.

Proposed resolution

Apply the same #[AutowireServiceClosure] pattern used by the fix in #3587604 to src/Hook/CommerceHooks.php: inject the inbox message fetcher as a \Closure and
dereference it at the call site in cron().

// Before                                                                                                                                                                                                                                                                    
  protected readonly InboxMessageFetcherInterface $inboxMessageFetcher,
  // ...                                                                                                                                                                                                                                                                                  
  $this->inboxMessageFetcher->fetch();
                                                                                                                                                                                                                                                                                          
  // After       
  #[AutowireServiceClosure('commerce.inbox_message_fetcher')]
  protected \Closure $inboxMessageFetcher,                                                                                                                                                                                                                                                
  // ...
  ($this->inboxMessageFetcher)()->fetch();                                                                                                                                                                                                                                          
  

The attached patch implements exactly this change. It does not alter any public API or behaviour — the call is still synchronous at hook_cron() time; the closure simply defers service resolution past container compilation.

Remaining tasks

  • Review the patch / MR.
  • Add a test that boots the container with a service that depends on logger.factory at construction time (mirroring the test added in #3587604, if any).
  • Commit to 3.x.

User interface changes

None.

API changes

None. CommerceHooks is not a public-API class.

Data model changes

None.

Release notes snippet

Fixed a service container circular reference between CommerceHooks, commerce.inbox_message_fetcher, and the logger factory that prevented bootstrap when another module depends on the logger factory at construction time (e.g.
acquia_connector). Follow-up to #3587604.

Issue fork commerce-3605829

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

plopesc created an issue. See original summary.

plopesc’s picture

Issue summary: View changes
Priority: Normal » Major
Status: Active » Needs review

MR created with the help of a LLM. Code has been tested and approved by a human before posting.

  • jsacksick committed e1865b0f on 3.x authored by plopesc
    fix: #3605829 Lazy-load InboxMessageFetcher in CommerceHooks to break...
    
jsacksick’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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.