8000 [HttpFoundation] Exception because HttpCache tries to access the container · Issue #40618 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

[HttpFoundation] Exception because HttpCache tries to access the container #40618

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
aschempp opened this issue Mar 29, 2021 · 9 comments
Closed

Comments

@aschempp
Copy link
Contributor
aschempp commented Mar 29, 2021

Symfony version(s) affected: 5.2.6

Description
The changes in #40497 can cause an exception if the container is not yet bootet. As far as I understand the HttpCache concept, the kernel SHOULD not be bootet for performance reasons if the request is in the cache. Therefore, the changes in #40497 must be wrong.

How to reproduce

Here's the exception trace we're getting in a Contao 4.11 setup. We're also using the FOSHttpCacheBundle and a custom entry point setup (not based on Symfony Flex)

PHP Fatal error:  Uncaught LogicException: Cannot retrieve the container from a non-booted kernel. in .../vendor/symfony/http-kernel/Kernel.php:307
Stack trace:
#0 .../vendor/symfony/framework-bundle/HttpCache/HttpCache.php(68): Symfony\Component\HttpKernel\Kernel->getContainer()
#1 .../vendor/friendsofsymfony/http-cache/src/SymfonyCache/EventDispatchingHttpCache.php(103): Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#2 .../web/index.php(31): Contao\ManagerBundle\HttpKernel\ContaoCache->handle(Object(Symfony\Component\HttpFoundation\Request))
#3 {main}
  thrown in .../vendor/symfony/http-kernel/Kernel.php on line 307

Possible Solution

As the HttpCache is imho not allowed to access container parameters, the only solution I can think of is keep behaviour in Symfony 4.4 and set Request::enableHttpMethodParameterOverride(); in the entry point.

/cc @xabbuh

@aschempp aschempp added the Bug label Mar 29, 2021
aschempp added a commit to aschempp/conflicts that referenced this issue Mar 29, 2021
see symfony/symfony#40618
Should be set to an exact version once this is fixed in Symfony
leofeyer pushed a commit to contao/conflicts that referenced this issue Mar 29, 2021
see symfony/symfony#40618
Should be set to an exact version once this is fixed in Symfony
@nicolas-grekas
Copy link
Member

Can you please confirm that #40619 fixes the issue ?

@aschempp
Copy link
Contributor Author

Hmm, I fail to understand how you can configure the HttpCache in the container, if the instance is supposed to run outside the kernel & container at all. Maybe @Toflar knows some details about that?

Not accessing $this->kernel->getContainer()... at runtime certainly fixes our issue though.

@Toflar
Copy link
Contributor
Toflar commented Mar 29, 2021

I don't see how HttpCache can be configured via container either, that makes no sense to me. The whole point of it is to ensure Symfony doesn't need to be booted. But maybe there have been changes to that concept lately.

@nicolas-grekas
Copy link
Member

You might have missed #37351
Fact is, both modes are supported since 5.2.

@Toflar
Copy link
Contributor
Toflar commented Mar 29, 2021

Ah, indeed. Thanks for the hint :)

@aschempp
Copy link
Contributor Author

Thanks for the PR link! Since the kernel seems now always bootet, shouldn't the enableHttpMethodParameterOverride always be called by the kernel instead? Looks like it might be called multiple times now if the request is not in cache?

@aschempp
Copy link
Contributor Author

I mean, since the kernel is always bootet, https://github.com/symfony/symfony/blob/5.x/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php#L95-L97 should always be called and the additional call shouldn't be necessary?

@nicolas-grekas
Copy link
Member

#40497 fixes #40452, which explains why this is needed. TLDR, HttpCache is run before bundles are booted.

chalasr added a commit that referenced this issue Mar 29, 2021
…ttp_cache (nicolas-grekas)

This PR was merged into the 5.2 branch.

Discussion
----------

[FrameworkBundle] dont access the container to configure http_cache

| Q             | A
| ------------- | ---
| Branch?       | 5.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #40618
| License       | MIT
| Doc PR        | -

Commits
-------

8aa6818 [FrameworkBundle] dont access the container to configure http_cache
@aschempp
Copy link
Contributor Author

Thanks for the quick fix @nicolas-grekas !

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

No branches or pull requests

4 participants
0