When I change the default cache class in settings.php using the following:
$settings['cache']['default'] = 'cache.backend.memcache';

I'm getting the error:

Failed to log error: Symfony\\Component\\DependencyInjection\\Exception\\ServiceCircularReferenceException: Circular reference detected for service "cache.backend.memcache", path: "http_kernel -> http_middleware.negotiation -> http_middleware.reverse_proxy -> http_middleware.page_cache -> cache.render -> cache.backend.memcache -> memcache.factory -> logger.channel.memcache -> logger.factory -> logger.syslog -> config.factory -> config.storage -> cache.config". in Drupal\\Component\\DependencyInjection\\Container->get() (line 147 of /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php). #0 /path/to/drupal/core/lib/Drupal/Core/Cache/ChainedFastBackendFactory.php(85): Drupal\\Component\\DependencyInjection\\Container->get('cache.backend.m...')\n#1 /path/to/drupal/core/lib/Drupal/Core/Cache/CacheFactory.php(83): Drupal\\Core\\Cache\\ChainedFastBackendFactory->get('config')\n#2 [internal function]: Drupal\\Core\\Cache\\CacheFactory->get('config')\n#3 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(254): call_user_func_array(Array, Array)\n#4 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\\Component\\DependencyInjection\\Container->createService(Array, 'cache.config')\n#5 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(494): Drupal\\Component\\DependencyInjection\\Container->get('cache.config', 1)\n#6 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(236): Drupal\\Component\\DependencyInjection\\Container->resolveServicesAndParameters(Object(stdClass))\n#7 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\\Component\\DependencyInjection\\Container->createService(Array, 'config.storage')\n#8 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(494): Drupal\\Component\\DependencyInjection\\Container->get('config.storage', 1)\n#9 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(236): Drupal\\Component\\DependencyInjection\\Container->resolveServicesAndParameters(Object(stdClass))\n#10 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\\Component\\DependencyInjection\\Container->createService(Array, 'config.factory')\n#11 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(494): Drupal\\Component\\DependencyInjection\\Container->get('config.factory', 1)\n#12 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(236): Drupal\\Component\\DependencyInjection\\Container->resolveServicesAndParameters(Object(stdClass))\n#13 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\\Component\\DependencyInjection\\Container->createService(Array, 'logger.syslog')\n#14 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(494): Drupal\\Component\\DependencyInjection\\Container->get('logger.syslog', 1)\n#15 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(329): Drupal\\Component\\DependencyInjection\\Container->resolveServicesAndParameters(Object(stdClass))\n#16 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\\Component\\DependencyInjection\\Container->createService(Array, 'logger.factory')\n#17 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(494): Drupal\\Component\\DependencyInjection\\Container->get('logger.factory', 1)\n#18 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(248): Drupal\\Component\\DependencyInjection\\Container->resolveServicesAndParameters(Array)\n#19 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\\Component\\DependencyInjection\\Container->createService(Array, 'logger.channel....')\n#20 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(494): Drupal\\Component\\DependencyInjection\\Container->get('logger.channel....', 1)\n#21 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(236): Drupal\\Component\\DependencyInjection\\Container->resolveServicesAndParameters(Object(stdClass))\n#22 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\\Component\\DependencyInjection\\Container->createService(Array, 'memcache.factor...')\n#23 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(494): Drupal\\Component\\DependencyInjection\\Container->get('memcache.factor...', 1)\n#24 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(236): Drupal\\Component\\DependencyInjection\\Container->resolveServicesAndParameters(Object(stdClass))\n#25 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\\Component\\DependencyInjection\\Container->createService(Array, 'cache.backend.m...')\n#26 /path/to/drupal/core/lib/Drupal/Core/Cache/CacheFactory.php(83): Drupal\\Component\\DependencyInjection\\Container->get('cache.backend.m...')\n#27 [internal function]: Drupal\\Core\\Cache\\CacheFactory->get('render')\n#28 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(254): call_user_func_array(Array, Array)\n#29 /path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\\Component\\DependencyInjection\\Container->createService(Array, 'cache.render')\n#30 /path/to/drupal/...

I have memcached installed and active on the server
I'm not adding any other configurations to settings.php file

any idea what is causing this error?

Comments

Aghiad created an issue. See original summary.

Aghiad’s picture

Issue summary: View changes
Aghiad’s picture

Issue summary: View changes
misc’s picture

Interesting - could you give some information about you setup, drupal version, php version etc. ?

Aghiad’s picture

Drupal version: 8.2.6
PHP version: 5.6.30
Memcache version: 3.0.8
Server: CentOS 7

I'm using PECL memcache

here is the content of /etc/httpd/conf.d/memcache.ini:

[memcache]
; Data will be transferred in chunks of this size
memcache.chunk_size = 32768
memcache.hash_strategy = consistent
memcache.default_port = 0
session.save_handler = memcache
session.save_path = "unix:///tmp/memcached.socket11:0?persistent=1&weight=1&timeout=1&retry_interval=15"

in /sites/default/settings.php I only added this line of code:

$settings['cache']['default'] = 'cache.backend.memcache';

misc’s picture

Could you first try to update drupal core and see if you get the same problem?

damiankloip’s picture

I think I know why here. Since we started injecting the logger a few days ago, so we could remove the old error handling function - see http://cgit.drupalcode.org/memcache/commit/?id=ed98d69 . So I would be almost certain that if you disabled syslog, just to test this, it would work fine. The trouble your are having is because the syslog logger has the config factory injected, which in turn uses the config cache, which then tries to get memcache, but memcache wants the logger :) It's kind of crappy that syslog has configuration injected, instead of settings.

So maybe memcache just needs to not use any loggers, and just throw exceptions.

hswong3i’s picture

Category: Support request » Bug report
Status: Active » Needs review
StatusFileSize
new6.08 KB

@damiankloip agree that syslog shouldn't use config cache since it is a base services... Anyway looking for core changes really take time, and most use case as mine will always enable both syslog and memcache so get into trobule...

I give a try to revert ed98d69, but also keep the changes of remove memcache.module by replacing the memcache_log_warning() with closures inside register_shutdown_function() (see this example). For sure that the implementation could be more elegant ;-)

Patch via memcache-8.x-2.x-dev, tested with Drupal core 8.3.4 and PHP-FPM 7.1.6, no more circular reference detected.

Aghiad’s picture

Thanks @hswong3i for the patch,
actually it worked!
and the error is gone

now I'm having another error. I think it's not related to this issue, but if you guys can help me I'll be thankful!
(I can open a new issue if you want)

here is the error:

Failed to log error: Drupal\\memcache\\MemcacheException: Memcache instance could not be initialized. Check memcache is running and reachable in Drupal\\memcache\\DrupalMemcacheFactory->get() (line 141 of/path/to/drupal/modules/memcache/src/DrupalMemcacheFactory.php). #0/path/to/drupal/modules/memcache/src/MemcacheBackendFactory.php(72): Drupal\\memcache\\DrupalMemcacheFactory->get('bootstrap')\n#1/path/to/drupal/core/lib/Drupal/Core/Cache/ChainedFastBackendFactory.php(85): Drupal\\memcache\\MemcacheBackendFactory->get('bootstrap')\n#2/path/to/drupal/core/lib/Drupal/Core/Cache/CacheFactory.php(83): Drupal\\Core\\Cache\\ChainedFastBackendFactory->get('bootstrap')\n#3 [internal function]: Drupal\\Core\\Cache\\CacheFactory->get('bootstrap')\n#4/path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(254): call_user_func_array(Array, Array)\n#5/path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\\Component\\DependencyInjection\\Container->createService(Array, 'cache.bootstrap')\n#6/path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(494): Drupal\\Component\\DependencyInjection\\Container->get('cache.bootstrap', 1)\n#7/path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(236): Drupal\\Component\\DependencyInjection\\Container->resolveServicesAndParameters(Object(stdClass))\n#8/path/to/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\\Component\\DependencyInjection\\Container->createService(Array, 'module_handler')\n#9/path/to/drupal/core/lib/Drupal/Core/DrupalKernel.php(544): Drupal\\Component\\DependencyInjection\\Container->get('module_handler')\n#10/path/to/drupal/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(45): Drupal\\Core\\DrupalKernel->preHandle(Object(Symfony\\Component\\HttpFoundation\\Request))\n#11/path/to/drupal/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\\Core\\StackMiddleware\\KernelPreHandle->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#12 ...

as I mentioned erlier, I'm using PECL memcache.

delta’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community

Applying the patch in #8 fix the issue.
Bump to major since the module doesn't work at all without this patch.

Thanks for the patch @hswong3i

misc’s picture

Tested and works fine here also.

damiankloip’s picture

Status: Reviewed & tested by the community » Needs work

I think in this case we should not bother trying to log to be honest. If E.g. you couldn't connect to memcache and still using the syslog handler which was also using the config cache (memcache), your logger wouldn't work either way. This is why I think we should just remove the attempt to log in these cases and just throw exceptions.

damiankloip’s picture

Priority: Major » Critical
Status: Needs work » Needs review
StatusFileSize
new5.6 KB
new2.61 KB
delta’s picture

Status: Needs review » Reviewed & tested by the community

Last patch work fine, I use it in production. +1 for throwing exception instead of using the logger which would be broken anyway in this case @damiankloip

damiankloip’s picture

ok, let's just get this in then! I'll cut another tag and release too.

  • damiankloip committed cd53ea6 on 8.x-2.x
    Issue #2887558 by damiankloip, hswong3i, delta, MiSc: Circular reference...
damiankloip’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

krystalcode’s picture

Raised issue in Drupal with potential solution: https://www.drupal.org/project/drupal/issues/3103620