-
Notifications
You must be signed in to change notification settings - Fork 71
Make sure sessions are cleaned after processing a request. #131
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
Conversation
Should fix #130 |
Could you add a test that shows the problem and then confirms the fix? @dnna has just added some test cases to the httpkernel bridge for Symfony in case the test needs to go there? |
To be honest I have never really liked this catch block. Its not just the session, basically none of the postHandle functions of the bootstrap are executed. Maybe it would be better to kill the worker and just log something in this scenario? Normally the the kernel shouldn't be throwing unhandled exceptions anyway. |
It seems that the kernel throws an exception when a class is not found. Not very unusual in a scripting language. |
It makes much sense to kill the worker. Now that I think of it, many issues I have encountered are related. E.g. a database transaction that is not committed or rolled back due to such an exception: my workaround is to send a rollback statement for every new request. Until now I had no idea what caused it. Killing the worker would solve that much better. |
@mathieudz yes exactly. My point was that if the kernel throws an exception, it means something went wrong and we don't really know if the kernel is suitable to be reused in the next request (its for the same reason that doctrine closes the entity manager if an SQL error occurs). So killing the worker is probably the best solution for this issue and should improve stability in general. |
Should we also revisit the doctrine handling currently implemented then? |
I think the current Doctrine handling is fine, it addresses issues that can occur even if the kernel does not throw an exception (for example Symfony may catch the exception and show its own error page). |
I still have session leaking with this patch. Anyone an idea how a worker can be killed from HttpKernel? |
Good question, the bridge does not have access to the slave. @andig what do you think? |
The reason that this patch doesn't work is because it only closes the session for PHP, but Symfony still considers it open and still has all data loaded. |
This would no longer be a topics if we kill the worker? Out of plain security considerations I like he suggestion by @dnna. Let the Otherwise we would need to do something in |
@mathieudz lets make this PR just remove the catch block completely, so the exception is allowed to bubble up. I will make a separate PR in https://github.com/php-pm/php-pm to catch it and shutdown the worker. |
@mathieudz Looking at what you wrote again I'm wondering- apart from proper exception handling- if we're missing anything for properly handling symfony sessions? |
PHP PM will catch any unexpected exception and kill the worker.
26a4356
to
d48ac40
Compare
@andig IMHO the real problem here is
A solution for the latter would be to reset all stateful Symfony services (request_stack, session, ...), but the former can only be solved by php-pm by killing the worker. Symfony does rely on the share-nothing architecture when things go wrong. |
I think we should limit the scope of this PR to only handle case 1 (request terminates improperly and not all listeners are executed) by killing the worker as discussed. Basically we remove the try-catch block from HttpKernel and let the exception bubble up to ProcessSlave (and catch it with the other PR). We can open a separate issue to discuss case 2, though personally I think its mostly fine, otherwise we would have noticed a lot more issues if session or request leaked under the normal workflow. |
OK for solving case 1 - that's my idea too. The PR has been updated for it. |
Reminder: need to require min ppm version when releasing this. |
@andig Reminding you of the reminder :) |
Darn. Why did we want to do this? It would typically pick up latest anyway? |
I think that latest phppm release + latest httpkernel release will crash on unhandled Symfony exceptions. This PR lets the exceptions bubble up, so you also need the PR of phppm that catches it. |
Oh yeah... fixed via 34327ed |
Sessions must also be cleaned up when Symfony throws an exception to avoid session leaking.