-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
DatabaseMigrations trait exhausts database connections #10619
Comments
This should happen anyway? |
When the applications are destroyed the connections should be garbage collected. Have you turned off the garbage collector? |
You definitely wouldn't want to do that. You'd want to call this->app->... |
Not that I'm aware of. Tested with
from https://launchpad.net/~ondrej/+archive/ubuntu/php5 for Ubuntu 14.04 LTS
Yeah, I thought so ... :-) The underlying |
Having the same issue with the DatabaseTransactions trait.
The above fix solves the issue for me.
|
I've switched my project from using the I replaced it with my own trait, not only because of this bug, but also because the included <?php
trait MultiDatabaseTransactionsTrait
{
/**
* @before
*/
public function beginDatabaseTransaction()
{
/** @var \Illuminate\Database\DatabaseManager $db */
$db = $this->app->make('db');
$names = array_keys($this->app['config']['database.connections']);
foreach ($names as $name) {
$db->connection($name)->beginTransaction();
}
$this->beforeApplicationDestroyed(function () use ($db, $names) {
foreach ($names as $name) {
$connection = $db->connection($name);
$connection->rollBack();
$connection->disconnect();
}
});
}
} |
Why closed? This issue isn't solved? |
Look at the PR linked above #10731 |
That PR did not fix the issue and does not work. The pr was closed not merged. |
This issue is still not solved. |
Did you read the PR? |
Being marked as a no-fix, or technical limitation. |
If someone has a really good fix, we're open to PRs. ;) |
I'm having problems with this too. Where is the better solution? |
@KNabityMailServicesLC just being an observer here, but as I see that the DatabaseTransaction code hasn't changed substantially since I created this issue, I think my #10619 (comment) still holds. I can confirm that it works insofar as the codebase is heavily developed on and the tests run locally and in our CI infrastructure many many times a day without known problems. |
So I seemed to solve this myself by setting persistent connections on in the configuration environment. I make it an env(), and set it to true in phpunit.xml. Not the best solution, but it seems to fix the issue. |
@cythrawll: Saved my day ;)
|
Using
DatabaseMigrations
with a lot of tests will exhaust all connections to the dabatase, i.e. they're not freed/returned to the system.How to reproduce, as suggested from http://laravel.com/docs/5.1/testing#resetting-the-database-after-each-test :
composer.phar create-project laravel/laravel --prefer-dist
cd laravel
.env
to point to a valid database connecionvendor/bin/phpunit
After a some tests they start to fail with the following error (or similar, depending on your DB):
PDOException: SQLSTATE[08004] [1040] Too many connections
Here's an example trace:
To fix this for my suite, I created a trait similar to this:
I would open a PR if someone points me in the right direction where the fix would be appropriate.
I tried this, which also worked:
The text was updated successfully, but these errors were encountered: