Skip to content
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

[3.4] Cannot redeclare class Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser #25334

Closed
gnutix opened this issue Dec 5, 2017 · 15 comments
Assignees

Comments

@gnutix
Copy link
Contributor

gnutix commented Dec 5, 2017

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.4.*
PHP version 5.6.25

Stacktrace

We're currently upgrading a Symfony project to 3.4 on PHP 5.6.25 and my colleague has been having this issue since I've added the following block of code to our AppKernel::registerContainerConfiguration method:

        $loader->load(function (ContainerBuilder $container) {
            $container->setParameter('container.autowiring.strict_mode', true);
            $container->setParameter('container.dumper.inline_class_loader', true);
            $container->addObjectResource($this);
        });

It only happened on a second request, and often it had to be a different request, not just the same one (aka refresh didn’t cause it).

He found two ways to make it work :

  1. Commenting out the line $container->setParameter('container.dumper.inline_class_loader', true);, or
  2. Commenting out the line $kernel->loadClassCache(); in app_dev.php

I personally can't reproduce the issue on my setup. Any idea what might be happening here ?

Also, it might look like we're not the only ones : https://stackoverflow.com/questions/47617879/symfony-duplicate-class-definition-in-cache

Thanks for your help.
gnutix

@rpac-tump
Copy link

His 1st way is ok for me, i can refresh without error.
The solution on stackoverflow doesn't work for now...

@nicolas-grekas
Copy link
Member

I think you need to remove this line from app*.php:
https://github.com/symfony/symfony-standard/blob/3.3/web/app.php#L7

@nicolas-grekas
Copy link
Member

Try also removing L12 btw (loadClassCache)

@gnutix
Copy link
Contributor Author

gnutix commented Dec 5, 2017

@nicolas-grekas That's indeed the second solution he found. However, I'm wondering why it happens and if it's a good idea to release standard code for Symfony that provoke this issue. I don't know the caching mechanism in details, but I guess there's an impact on performance for both solutions (disabling the inline dumper or the loadCacheClass) ?

I was also thinking that these code lines in app(_dev).php are not at all documented, and it might make sense to comment them (especially if they can or should be removed under certain circumstances). WDYT ?

@nicolas-grekas
Copy link
Member

Alternatively, can you try to turn container.dumper.inline_class_loader to false? and then to remove it?
(while reverting the previous change)

@weaverryan
Copy link
Member

So are those 2 settings (loadClassCache and inline_class_loader) incompat? Is there something that needs fixing or not?

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Dec 5, 2017

There are incompatible, but that should be already handled:
https://github.com/symfony/symfony/blob/3.4/src/Symfony/Component/HttpKernel/Kernel.php#L842

dunno what's missing - maybe a PHP version check also, adding \PHP_VERSION_ID >= 70000 to the existing check.

@gnutix some more debugging hints would help (also trying this additional check please)

@gnutix gnutix closed this as completed Dec 5, 2017
@gnutix gnutix reopened this Dec 5, 2017
@gnutix
Copy link
Contributor Author

gnutix commented Dec 5, 2017

Setting container.dumper.inline_class_loader to false resolves the issue. Same when using:

'inline_class_loader_parameter' => \PHP_VERSION_ID >= 70000 && !$this->loadClassCache && !class_exists(ClassCollectionLoader::class, false) ? 'container.dumper.inline_class_loader' : null,

along with container.dumper.inline_class_loader set to true.

@nicolas-grekas nicolas-grekas self-assigned this Dec 6, 2017
fabpot added a commit that referenced this issue Dec 7, 2017
This PR was merged into the 3.4 branch.

Discussion
----------

[HttpKernel] Disable inlining on PHP 5

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #25334
| License       | MIT
| Doc PR        | -

Commits
-------

950fd99 [HttpKernel] Disable inlining on PHP 5
@fabpot fabpot closed this as completed Dec 7, 2017
@gnutix
Copy link
Contributor Author

gnutix commented Dec 7, 2017

Thanks Nicolas for the fix. So the idea is that the AppKernel.php codes enables it, and behind the scene it's disabled for PHP < 7. Guess that's alright for such a "not-well-know" optimization parameter, but still I find it a bit strange. We do have PHP 7 conditions in app.php/app_dev.php so it's explicit. Why not in AppKernel too ?

@seblegall
Copy link

Thx for the fix @nicolas-grekas. We just crashed the all Meetic website due to this error. :-) I guess we will wait for the 4.4.2 to be release before upgrading to sf 3.4.

@sroze
Copy link
Contributor

sroze commented Dec 14, 2017

@seblegall You mean 3.4.2, right? 😄

@seblegall
Copy link

Yeah, of course. ;-)

@paicasso
Copy link

paicasso commented Jan 2, 2018

Right after installing a SF 3.4.1 it worked fine, but only after a server restart everything crashed getting the same error!

@mehdimabrouk
Copy link
Contributor

You can upgrade to symfony3.4.2 and resolve the problem

@bennet-enqos
Copy link

I just removed the files in var/cache/prod and var/cache/dev inside the project folder. It worked for me

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

No branches or pull requests

10 participants