Problem/Motivation

When using this module version 4.x in on Drupal 9.5.x, I got a circular reference error:

Circular reference detected for service "restrict_by_ip.current_user", path  
  : "asset.css.collection_optimizer -> asset.css.dumper -> file_system -> log  
  ger.channel.file -> restrict_by_ip.current_user -> restrict_by_ip.role_fire  
  wall -> restrict_by_ip.ip_tools".  
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

StijnStroobants created an issue. See original summary.

stijnstroobants’s picture

StatusFileSize
new2.01 KB
stijnstroobants’s picture

StatusFileSize
new2.01 KB
stijnstroobants’s picture

Status: Needs work » Needs review
darvanen’s picture

Status: Needs review » Postponed (maintainer needs more info)

I'm sorry, I don't see what renaming the config property of these classes could possibly have to do with a circular reference to a `recript_by_ip.current_user` service which is not even defined by this module.

I'm postponing this issue pending further explanation and may close later if there is no activity.

[edit: I see that service is actually defined by this module, I missed it the first time around - however the remainder of this comment stands]

bburg’s picture

I ran into this today. Here's a description provided by Claude Code:

The cause is structural, not config-related — the OP's property-rename patches are a red herring (darvanen's skepticism is correct).

restrict_by_ip decorates current_user and gives the decorator a heavy dependency subtree (restrict_by_ip.role_firewall → ip_tools / entity_type.manager). Whenever anything in that subtree transitively needs a logger, you get a cycle, because logging depends on current_user — which is now the decorator. The OP's path entered via logger.channel.file; on an Acquia stack it enters via acquia_connector → logger.factory. Same loop, different trigger.

This got worse in Drupal 10.3: core made current_user a hard constructor argument of logger.factory (change record). That turns this from an intermittent cycle (depends on whether a logger channel is eagerly built) into a deterministic failure on 10.3+ — it reliably breaks drush deploy when acquia_connector is enabled.

Minimal fix: mark restrict_by_ip.role_firewall as lazy: true so the current_user decorator receives a lazy proxy and its subtree isn't instantiated at container-compile time. This requires committing a generated proxy class (core/scripts/generate-proxy-class.php 'Drupal\restrict_by_ip\RoleFirewall' 'modules/contrib/restrict_by_ip/src'). Verified against 4.0.0-beta3 on Drupal 10.6: drush cr / drush updatedb pass and role-stripping still works.

Longer term, decorating current_user is inherently fragile (everything depends on it, so any added dependency is a latent cycle) — an event-subscriber approach to role stripping would avoid the decoration path entirely.

Attached is the patch it came up.

darvanen’s picture

Status: Postponed (maintainer needs more info) » Needs review

Thanks @bburg I'll take a look

darvanen’s picture

Version: 8.x-4.x-dev » 9.x-dev
Assigned: Unassigned » darvanen
Status: Needs review » Needs work

I've been working on a new major version which includes an architectural overhaul, I'll put the full change in there and release an alpha soon.

darvanen’s picture

Assigned: darvanen » Unassigned
Status: Needs work » Needs review
StatusFileSize
new19.16 KB

@bburg it turns out the work applied cleanly to 8.x-4.x as well, would you mind trying it out? I'm attaching it as a patch for ease.

  • darvanen committed 444a29f1 on 9.x
    fix: #3394774 Circular reference detected for service "restrict_by_ip....
darvanen’s picture

Version: 9.x-dev » 8.x-4.x-dev

I've committed to 9.x so I can continue with other improvements, awaiting feedback on 8.x-4.x since that's in use on live sites.