schmittjoh / JMSDiExtraBundle

Provides Advanced Dependency Injection Features for Symfony2
http://jmsyst.com/bundles/JMSDiExtraBundle
330 stars 130 forks source link

[2.2] Random 500 Redeclare Symfony\Bundle\FrameworkBundle\Controller\Controller #95

Open emgiezet opened 11 years ago

emgiezet commented 11 years ago

Hi!

I got this 500 randomly once or twice per 10 requests.

FatalErrorException: Compile Error: Cannot redeclare class Symfony\Bundle\FrameworkBundle\Controller\Controller in /home/mgz/workspace/Interim/cms/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php line 254

Here is the trace:

in /home/mgz/workspace/Interim/cms/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php line 254
at ErrorHandler->handleFatal() in /home/mgz/workspace/Interim/cms/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php line 0
at ControllerInjectorsWarmer->findControllerClasses() in /home/mgz/workspace/Interim/cms/vendor/jms/di-extra-bundle/JMS/DiExtraBundle/HttpKernel/ControllerInjectorsWarmer.php line 35
at ControllerInjectorsWarmer->warmUp() in /home/mgz/workspace/Interim/cms/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php line 47
at CacheWarmerAggregate->warmUp() in /home/mgz/workspace/Interim/cms/app/bootstrap.php.cache line 601
at Kernel->initializeContainer() in /home/mgz/workspace/Interim/cms/app/bootstrap.php.cache line 378
at Kernel->boot() in /home/mgz/workspace/Interim/cms/app/bootstrap.php.cache line 409
at Kernel->handle() in /home/mgz/workspace/Interim/cms/web/app_dev.php line 18
at ??{main}() in /home/mgz/workspace/Interim/cms/web/app_dev.php line 0

Project is basic configured sf 2.2 with sonata & fosuserbundle with APC and Memcached. It happens on dev env.

schmittjoh commented 11 years ago

Are you using the compiled class file? If so, can you try whether you get the error when you disable it?

Did this error occur on Symfony 2.1?

stof commented 11 years ago

@schmittjoh FYI, sonata removed their controllers from the compiled class file in their 2.1 branch recently but it has not yet been merged into master for 2.2. But DIExtraBundle should not break when it is used IMO.

emgiezet commented 11 years ago

This happens when I'm using clean symfony generated controllers o FOSUserBundle login/register actions. It's not connected with sonata.

schmittjoh commented 11 years ago

@emgiezet, you'll need to give some more precise debugging details like the exact versions, whether or not you use the compiled class cache, whether or not this happened on Symfony 2.1 (if you upgraded).

@stof, I'm all for not breaking things if this is possible. In order to assess this, we first need to find the cause though, and by cause I do not mean the class in which it happens, but why it happens now and has not happened before.

stof commented 11 years ago

the reason is that the cache warmer is requiring all controllers, which break if one of them was defined in the bootstrap file

schmittjoh commented 11 years ago

I'm aware that compiled controllers are not supported by this bundle, and if @emgiezet can confirm that this is indeed causing the issue for him, then we would need to see when this class was added to the compiled files, and remove it again.

This is not only necessary for the cache warmer to work, but also required to keep annotation parsing at an acceptable performance level. Then, we could also look into providing a better error message for these cases, but at this point, I do not know what we could except parsing all files before including them, or removing the cache warmer.

Seldaek commented 11 years ago

@schmittjoh how about checking if the controller class exists already before requiring the file? I'm not sure why the bundle requires them instead of relying on autoloading anyway? Obviously this would break if people don't follow PSR-0, but I don't know if that's really an issue in sf2 projects.