-
-
Notifications
You must be signed in to change notification settings - Fork 454
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
Close connections and clear managers on shutdown #366
Conversation
Is this just a matter of tests? What if I want to re-use a connection from a kernel after the kernel has been shut down (for example for late batch-processing of a 201 or 202 request)? |
@Ocramius in a web context, the kernel is never shut down. A kernel.terminate action happens after handling the request and sending the response, but not after shutdown The main action of shutting down the kernel is removing the reference to the container, so that booting again recreates a new container (your existing container would ultimately be garbage collected but not immediately because of circular object graphs). The goal of the shutdown is to reset your kernel instance entirely. the only use case I see is testing (to isolate your tests while keeping the same kernel reference). |
When shutting down the kernel, the connections should be closed to avoid leaking connections during tests, which could reach the connection limit. The entity managers should also cleared to give more chances to entities to be garbage collected. Closes Behat/Symfony2Extension#52
e88172a
to
79bc1e4
Compare
Just a FYI but I also encountered this when running unit tests. I'm not using Symfony but I'm using Laravel 4.2 + Doctrine (DBAL 2.5.1). A simple connection |
👍 need this. |
I'm going to merge this one. Writing an integration test for the shutdown would be a pain |
This PR was merged into the 1.3.x-dev branch. Discussion ---------- Close connections and clear managers on shutdown When shutting down the kernel, the connections should be closed to avoid leaking connections during tests, which could reach the connection limit. The entity managers should also cleared to give more chances to entities to be garbage collected. Closes Behat/Symfony2Extension#52 Commits ------- 79bc1e4 Close connections and clear managers on shutdown
This change creates issues on my side as per the following simplified test. public function testCloseRoute()
{
$task = $this->createTask();
$this->callRoute('task_close', array('id' => $task->getId()));
$this->assertEquals(302, $this->client->getResponse()->getStatusCode());
$this->client->followRedirect();
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->removeEntity($task);
} After this change I am getting the error:
A $em->merge() is not working as the entity is stated as not found. What would you recommend as workaround? |
When shutting down the kernel, the connections should be closed to avoid leaking connections during tests, which could reach the connection limit. The entity managers should also cleared to give more chances to entities to be garbage collected.
Closes Behat/Symfony2Extension#52