Skip to content

Symfony 7.3 cannot boot if the kernel implements CompilerPassInterface #60191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lyrixx opened this issue Apr 10, 2025 · 3 comments · Fixed by #60392
Closed

Symfony 7.3 cannot boot if the kernel implements CompilerPassInterface #60191

lyrixx opened this issue Apr 10, 2025 · 3 comments · Fixed by #60392

Comments

@lyrixx
Copy link
Member

lyrixx commented Apr 10, 2025

Symfony version(s) affected

7.3.latest

Description

If the kernel implements CompilerPassInterface, Symfony cannot boot (only in HTTP, cli is OK)

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException:
Service "kernel" not found: the container inside "Symfony\Component\DependencyInjection\Argument\ServiceLocator" is a smaller service locator that only knows about the "security.route_loader.logout" service.

  at /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/DependencyInjection/ServiceLocator.php:137
  at Symfony\Component\DependencyInjection\ServiceLocator->createNotFoundException()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Contracts/Service/ServiceLocatorTrait.php:48)
  at Symfony\Component\DependencyInjection\ServiceLocator->doGet()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/DependencyInjection/ServiceLocator.php:43)
  at Symfony\Component\DependencyInjection\ServiceLocator->get()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/DependencyInjection/Argument/ServiceLocator.php:34)
  at Symfony\Component\DependencyInjection\Argument\ServiceLocator->get()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/Routing/Loader/ContainerLoader.php:37)
  at Symfony\Component\Routing\Loader\ContainerLoader->getObject()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/Routing/Loader/ObjectLoader.php:45)
  at Symfony\Component\Routing\Loader\ObjectLoader->load()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/Config/Loader/DelegatingLoader.php:37)
  at Symfony\Component\Config\Loader\DelegatingLoader->load()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php:65)
  at Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader->load()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php:72)
  at Symfony\Bundle\FrameworkBundle\Routing\Router->getRouteCollection()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/Routing/Router.php:282)
  at Symfony\Component\Routing\Router->getMatcherDumperInstance()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/Routing/Router.php:218)
  at Symfony\Component\Routing\Router->Symfony\Component\Routing\{closure}()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/Config/ResourceCheckerConfigCacheFactory.php:34)
  at Symfony\Component\Config\ResourceCheckerConfigCacheFactory->cache()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/Routing/Router.php:216)
  at Symfony\Component\Routing\Router->getMatcher()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/Routing/Router.php:182)
  at Symfony\Component\Routing\Router->matchRequest()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php:101)
  at Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php:115)
  at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:206)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:56)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php:122)
  at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:159)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:76)
  at Symfony\Component\HttpKernel\HttpKernel->handle()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/HttpKernel/Kernel.php:182)
  at Symfony\Component\HttpKernel\Kernel->handle()
     (/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/Runtime/Runner/Symfony/HttpKernelRunner.php:35)
  at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run()
     (vendor/autoload_runtime.php:29)
  at require_once('/home/gregoire/dev/tmp/sf.7.3/vendor/autoload_runtime.php')
     (public/index.php:5)           

How to reproduce

symfony new --webapp sf.7.3
cd sf.7.3
/home/gregoire/dev/github.com/lyrixx/symfony/link 
code src/Kernel.php 

Possible Solution

No response

Additional Context

No response

@ro0NL
Copy link
Contributor

ro0NL commented Apr 10, 2025

im wondering if we can reproduce it using GHA :)

maybe not this specific case, but at least a default install

@lyrixx
Copy link
Member Author

lyrixx commented Apr 10, 2025

I edited the kernel to implements CompilerPassInterface. But yes, should be quite easy

@Jean-Beru
Copy link
Contributor

The kernel service is excluded due to the autoconfiguration of CompilerPassInterface.

It can be fixed by reverting this configuration for services implementing KernelInterface too but I'm not sure this it is the best way to go about it 🤔

Ex:

diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveInstanceofConditionalsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveInstanceofConditionalsPass.php
index 90d4569c42..023dc7068a 100644
--- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveInstanceofConditionalsPass.php
+++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveInstanceofConditionalsPass.php
@@ -16,6 +16,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
 use Symfony\Component\DependencyInjection\Definition;
 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
 use Symfony\Component\DependencyInjection\Exception\RuntimeException;
+use Symfony\Component\HttpKernel\KernelInterface;
 
 /**
  * Applies instanceof conditionals to definitions.
@@ -68,6 +69,7 @@ class ResolveInstanceofConditionalsPass implements CompilerPassInterface
         $instanceofBindings = [];
         $reflectionClass = null;
         $parent = $definition instanceof ChildDefinition ? $definition->getParent() : null;
+        $isKernel = is_subclass_of($class, KernelInterface::class);
 
         foreach ($conditionals as $interface => $instanceofDefs) {
             if ($interface !== $class && !($reflectionClass ??= $container->getReflectionClass($class, false) ?: false)) {
@@ -78,6 +80,11 @@ class ResolveInstanceofConditionalsPass implements CompilerPassInterface
                 continue;
             }
 
+            // Skip exclusion for Kernel added in FrameworkBundle
+            if ($isKernel && CompilerPassInterface::class === $interface) {
+                continue;
+            }
+
             foreach ($instanceofDefs as $key => $instanceofDef) {
                 /** @var ChildDefinition $instanceofDef */
                 $instanceofDef = clone $instanceofDef;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants