Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Security component listeners added multiple times when reusing the kernel for multiple requests #8244

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
pvandommelen opened this issue Jun 10, 2013 · 7 comments
Labels

Comments

@pvandommelen
Copy link
Contributor

I am trying to re-use the $kernel object like this:

$kernel = new AppKernel('prod', false);

$response1 = $kernel->handle($request1);
$kernel->terminate($request1, $response1);

$response2 = $kernel->handle($request2);
$kernel->terminate($request2, $response2);

This is obviously a use-case which not too many have tried, but here I am. I was surprised that most components seem to be well behaved in this regard. Currently I have only found two initializations in the security component that incorrectly add listeners.

I would like to propose two guidelines for initialization in general:

  1. Initial run check should happen through checking $this->is_initialized (or whatever) instead of checking for HttpKernelInterface::MASTER_REQUEST
  2. (Service) initialization should not depend on the request object

ContextListener::handle() does not comply with the first. It registers a listener on every master request causing a leak. Easy fix.

Firewall::onKernelRequest() does not with the second. It registers all applicable listeners through getListeners($event->getRequest()) on every master request causing a leak and potentially incorrect listeners from another firewall to be applied. A proper solution would require a restructure on how different firewalls exist within an application I think. I'm a bit out of my league here, but I think a general exception listener with a reference to the configuration should do it.

A different solution might consist of clearing the old listeners before registring the new, but that seems uglier to me.

What obvious things did I miss? Is everyone ok with enabling a single kernel to handle multiple requests?

@fabpot
Copy link
Member

fabpot commented Sep 6, 2013

@pvandommelen Can you check that #8946 fixes the problem for you?

@pvandommelen
Copy link
Contributor Author

@fabpot I haven't had the time yet to take a good look at it but the change in ExceptionListener looks suspicious. The leak is in registering the listener while the "fix" would only remove it when an actual exception occurs. I will take a better look sometime this week.

@fabpot
Copy link
Member

fabpot commented Sep 15, 2013

@pvandommelen You're right, that's why I made another patch after the introduction of the new request finish event: 1b2ef74

@cordoval
Copy link
Contributor

@pvandommelen how can you receive two requests? just curious

also you don't ->send() any of the responses before the terminates

@pvandommelen
Copy link
Contributor Author

My code above is not the code I would actually be using. The idea we had that is while symfony is pretty fast, its (classloading, services) initialization isn't. We could have a continuously running (stateful) worker accepting requests and returning responses without shutting down. My initial test using beanstalkd (something from the php react project is probably better) to transfer serialized requests and responses had some promising results performance-wise.

Running these tests I came across the leaks. Not sure if this will ever be used since I haven't spend much time on it since, but it's still very cool.

@cordoval
Copy link
Contributor

oh so you are basically saying to have multiple frontends, well at least one and the one front controller consuming a queue/socket with requests! So to parallelize and max performance I guess. Very nice!

@pvandommelen
Copy link
Contributor Author

Looks good to me.

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

No branches or pull requests

3 participants