-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
5.4.0: SessionListener::onKernelResponse
listener is registered twice in test env
#44345
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
Comments
Friendly ping @alexander-schranz |
We did replace the A workaround maybe would here that we replace the @mhujer can you check if you comment the following lines out and so avoid the additional SessionListener. If then work all correctly?: https://github.com/alexander-schranz/symfony/blob/b3e4f6657c0c47e1b5ba85e4554a3c273ee61066/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.php#L38-L46 |
@alexander-schranz yes, commenting out the suggested lines fixes the issue (the listener is registered only once). If anyone else is facing the similar issue, I added this as a workaround to my Kernel class and the tests are now passing: ...
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
...
class Kernel extends BaseKernel implements CompilerPassInterface
{
...
public function process(ContainerBuilder $container): void
{
if ($this->environment !== 'test') {
return;
}
// fix https://github.com/symfony/symfony/issues/44345
$container->removeDefinition('test.session.listener');
} |
@mhujer Thank you for testing this out. So we should make sure that only one session listener is registered. @jderusse What do you think that we alias symfony/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php Line 341 in 60ce5a3
if (!empty($config['test'])) {
// test listener will replace the exist session
8000
listener
// we are aliasing to avoid duplicated registered events
$container->setAlias('session_listener', 'test.session.listener');
} |
…lexander-schranz) This PR was squashed before being merged into the 5.4 branch. Discussion ---------- Avoid duplicated session listener registration in tests | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #44345 | License | MIT | Doc PR | - Avoid duplicated session listener registration in tests. Commits ------- 366cb1a Avoid duplicated session listener registration in tests
Symfony version(s) affected
5.4.0
Description
Symfony\Component\HttpKernel\EventListener\SessionListener::onKernelResponse()
listener is registered twice intest
environment.Our tests for controllers where we set
NO_AUTO_CACHE_CONTROL_HEADER
flag started failing, because the flag is reset on the first call ofonKernelResponse
and the subsequent call overwrites the previously set headers.How to reproduce
It works fine on 5.3:
But is registered twice on 5.4:
Possible Solution
No response
Additional Context
Note: The listener is set only once in
dev
andprod
envs.I guess that the issue may be related to #41390.
The text was updated successfully, but these errors were encountered: