Potential circular dependency in ServerManager
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3231532. -->
Reported by: [pfrenssen](https://www.drupal.org/user/382067)
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>There is a potential circular dependency between <code>ServerManager</code> and <code>CasMockServerConfigOverriderTest</code>. They do not directly depend on each other, but the circular dependency can be triggered by third party cache tag invalidator services.</p>
<p>I noticed this in the wild when I updated the Config Ignore module to the latest 3.0-beta1 release. In this release a new cache tag invalidator is introduced which depends on the <code>ConfigFactory</code> service. <code>ConfigFactory</code> will include our <code>CasMockServerConfigOverrider</code> in the dependency chain, and this depends on our <code>ServerManager</code> so it can check if the server is running before it applies the config override. The <code>ServerManager</code> in turn depends on the <code>CacheTagsInvalidator</code> so it can clear caches whenever the server is started or stopped. This causes an endless loop and the following exception is thrown:</p>
<pre>Circular reference detected for service "cas_mock_server.server_manager", path: "cas_mock_server.server_manager -> cache_tags.invalidator -> config_ignore.event_subscriber -> config.factory -> cas_mock_server.config_overrider". (Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException)</pre><h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<ol>
<li>Install the Cas mock server.</li>
<li>Install Config Ignore 3.0-beta1</li>
<li>Instantiate the <code>ServerManager</code> service in scope of a fully bootstrapped Drupal kernel, e.g. by executing our Behat scenario hook <code>CasMockServerContext::startMockServer()</code>.</li>
</ol>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>A simple solution would be to side load the cache tags invalidator service on demand, rather than declaring it as a fixed dependency in <code>ServerManager</code>.</p>
issue