Problem/Motivation

Steps to reproduce:

Add basic_auth to standard.info.yml, try to install with another language than EN.

This happens:

Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException: Circular reference detected for service "current_user", path: "plugin.cache_clearer -> plugin.manager.menu.local_action -> access_manager -> url_generator -> route_processor_manager -> route_processor_csrf -> csrf_token -> current_user -> authentication -> authentication.basic_auth -> user.auth". in Symfony\Component\DependencyInjection\Container->get() (line 283 of .../core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Container.php).

The problem is that in the constructor of basic auth auth provider and UserAuth, we call $entity_manager->getStorage(), which looks up definitions if this happens during a plugin cache clear after installing a module, then it does @Translation('User') or similar, which goes into the LocaleLookup cache, which needs the user roles. Boom.

Proposed resolution

The workaround is fairly easy: Do not call $entity_manager->getStorage() in the constructor of those services, instead keep the entity manager around.

This makes sense anyway (those services are invoked on every request and shouldn't create stuff they might not need) but it's very fragile...

Remaining tasks

User interface changes

API changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir’s picture

Status: Active » Needs review
FileSize
3.14 KB

Setting to critical because enabling basic_auth on a non-english site will make it kaputt.

Berdir’s picture

Issue tags: +Needs tests

Will need some tests I guess...

Status: Needs review » Needs work

The last submitted patch, 1: do-not-call-storage-in-construct-2241461-1.patch, failed testing.

juampynr’s picture

FileSize
76.81 KB

Possibly unrelated: after applying the patch and while running the installer I saw this error once all modules got installed:

juampynr’s picture

Ignore my above comment. My local db was not cleared up before reinstalling.

Now looking into those failing tests.

Berdir’s picture

I think I just forgot to update one of the $this->userStorage in those classes.

juampynr’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
848 bytes
3.59 KB

There was a missing line that needed to be changed. Let's see if all tests pass now.

Status: Needs review » Needs work

The last submitted patch, 7: do-not-call-storage-in-construct-2241461-6.patch, failed testing.

Berdir’s picture

Ok, here we go, extended InstallerTranslationTest to enable basic_auth through the UI, so that we can do it in a non-english context, this fails as expected.

Also fixed the unit test to no longer assume how often getStorage() is called, because it is called as often as we need it, which is ok, we have an optimized static cache for entity storages.

Berdir’s picture

The last submitted patch, 9: do-not-call-storage-in-construct-2241461-9-test-only.patch, failed testing.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

+1

juampynr’s picture

Looks good to me too.

catch’s picture

Feels like the circular reference here is really because translate entity info when it's requested as opposed to rendered. Most of the time we don't care what the translations are, certainly not in this case. That would require #1213510: A modern t() to fix though.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

Opened #2244447: Translation of low-level info/annotations leads to circular dependencies because I agree with berdir this seems extremely fragile still.

catch’s picture

Status: Fixed » Reviewed & tested by the community

I haven't successfully pushed this yet. Git prompted me for a password locally, and drupalcode.org is a 500. Will try to remember to push later, but re-opening so we don't discover a missing commit in two months...

  • Commit 0b80769 on 8.x by catch:
    Issue #2241461 by Berdir, juampy: Locale + basic_auth results in...
Berdir’s picture

Status: Reviewed & tested by the community » Fixed

#17 says this is now pushed.

Status: Fixed » Closed (fixed)

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