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 injectsInboxMessageFetcherInterface.InboxMessageFetcherdirectly injectscommerce.logger, which is a factory call back tologger.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
- 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). - Run
drush updatedb:statusordrush cr. - 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.factoryat 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
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
Comment #3
plopescMR created with the help of a LLM. Code has been tested and approved by a human before posting.
Comment #5
jsacksick commented