|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81113 PDO holds some non-GCable reference
Submitted: 2021-06-08 08:42 UTC Modified: 2021-06-09 10:06 UTC
From: m at m dot cz Assigned:
Status: Not a bug Package: PDO related
PHP Version: 8.0.7 OS: any
Private report: No CVE-ID: None
 [2021-06-08 08:42 UTC] m at m dot cz

When DBAL connection is closed manually - all references to PDO connection are removed manually (by ) - then PDO connection is released correctly.

But when there is no reference to an object holding the PDO connection (in this case Doctrine\DBAL\Connection), PDO connection is NOT released when GC is run.

I belive PDO holds some reference which is not decreased during GC cycle.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-06-08 08:52 UTC]
Which PDO driver do you use?
 [2021-06-08 09:31 UTC] m at m dot cz
At least pdo_mysql is affected, as when max. connection count is limited (by ALTER USER user@% WITH MAX_USER_CONNECTIONS 10;), connection limit is hit.
 [2021-06-08 11:52 UTC]
Okay, I think this will need some more reduced code to make progress. PDO generally does support GC, and since PHP 8.1 also supports per-driver GC. So this probably requires that some specific feature is being used.
 [2021-06-08 12:31 UTC] m at m dot cz
It seems it is related with:
which describes a GC issue when PDO class is extended, hovewer, it is marked as "not a bug". Why it is not a bug or is it technically impossible to provide full GC support?
 [2021-06-08 12:44 UTC]
I tried this script based on the dbal issue, but it does not show a memory leak on PHP 8.1 (or PHP 8.0, or PHP 7.4). So whatever issue that hit, it seems to have been fixed. The memory leak reported in bug #75190 is also fixed.

If there is some reasonably minimal way to reproduce, I'm happy to address other GC problems as well. I don't want to reduce this down from "using doctrine dbal, somewhere, somehow" though.
 [2021-06-09 10:04 UTC] m at m dot cz
I have futher looked into this issue with following:

a) the main issue is that PHPUnit TestCase is instanciated per test (correct), but PHPUnit does not destroy these instances after the test is completed, but keep that instances referenced until all tests are done (wrong, but PHP works correctly). PHPUnit issue:

b) even then gc_collect_cycles() is needed to be called at least twice. Reported as

This bug report can be closed.
 [2021-06-09 10:06 UTC]
-Status: Open +Status: Not a bug
 [2021-06-09 10:06 UTC]
Closing per above comment.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 06:01:29 2024 UTC