auditor-bundle
auditor-bundle copied to clipboard
Codeception: memory leak.
Q | A |
---|---|
auditor-bundle version |
4.1.0 |
PHP version | 7.4.19 |
Database | PostgreSQL |
Summary
Memory leak when running Codeception test.
Current behavior
After running several tests the test fails on memory exhausted. Error
- HookCest: Test failPHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 4194312 bytes) in /var/www/vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Logger/LoggerChain.php on line 19
{
"success": false,
"data": {
"exception": {},
"error": "Error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 4194312 bytes)",
"file": "\/var\/www\/vendor\/damienharper\/auditor\/src\/Provider\/Doctrine\/Auditing\/Logger\/LoggerChain.php",
"line": 19,
"code": "6507276015"
}
}
My assumption the damienharper/auditor/src/Provider/Doctrine/Auditing/Logger/LoggerChain
keep track of all queries in memory and does not clear it between tests.
All tests surrounded by the transaction which rolls back after test completion to keep the database clean between tests (I think it is important to notice).
How to reproduce
Try to use Symfony with codeception and write a bunch of tests what write to the database.
Expected behavior
The codeception test do not make memory leak.
I noticed the same thing, while it would not run out of memory due to a fairly high memory limit, the test suite would slow down exponentially to a point where 223 tests would take over 40 minutes to complete (before the upgrade it would take about 20-25 seconds).
A blackfire profile run showed that DH\Auditor\Provider\Doctrine\Auditing\Event\DoctrineSubscriber::onFlush
was called 115k times with wall time of 36 min and DH\Auditor\Provider\Doctrine\Auditing\Logger\LoggerChain::addLogger
was called 1 741 327 704 times, wall time 7 min.
As a workaround I disabled the AuditorBundle for the test environment.
Thanks @Legion112 @Liiva for the report. I'll have a look at it asap (very busy lately). @Liiva would you mind sharing your backfire profiles?
@DamienHarper Any chance you had a chance to look at this? I ran into the same problem.
Codeception uses a shared memory for all functional tests (https://codeception.com/docs/04-FunctionalTests#shared-memory).
This was never a problem and I could run ~500 tests, which used about 300 MB. After installing the auditor-bundle my tests fail after ~100 tests, because they exceed the memory limit of 1024 MB.
@Legion112 @Liiva @Siegii As I do not use Codeception, would you mind providing a complete code sample (as a GitHub repo for example) that reproduce the issue? This would greatly help
Any update on this?