[8.x] Close doctrineConnection on disconnect #41584
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Consider this test:
With a migration that modify a column:
On PostgreSQL, after the 100th iteration, this error will pop up:
While disconnect sets the “main” PDO object as
null
, the Doctrine connection created by the “change” action is not. The actual connection to the database is not actually closed in this specific case as the underlying PDO object is not fully destroyed as per PHP Documentation: https://www.php.net/manual/en/pdo.connections.php.This bug won't affect any migration that are not modifying a column, as the Doctrine Connection is only created when needed, eg. using
->change()
.I understand this fix won’t have much impact on a normal Laravel install, as :
tearDown()
, Connection included, closing the Doctrine connection.parent::tearDown();
But in a situation where
disconnect()
is called outside of a test scenario, or anyone not using the whole Laravel TestCase might encounter this issue.References :
$connectionsToTransact
#20340