Skip to content
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

Codeception: memory leak. #264

Open
Legion112 opened this issue Jun 9, 2021 · 5 comments
Open

Codeception: memory leak. #264

Legion112 opened this issue Jun 9, 2021 · 5 comments
Labels
bug Something isn't working feedback needed Further information is requested

Comments

@Legion112
Copy link

Legion112 commented Jun 9, 2021

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.

@Legion112 Legion112 added the bug Something isn't working label Jun 9, 2021
@Liiva
Copy link

Liiva commented Jun 28, 2021

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.

@DamienHarper
Copy link
Owner

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?

@Siegii
Copy link

Siegii commented Jun 29, 2022

@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.

@DamienHarper
Copy link
Owner

@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

@DamienHarper DamienHarper added the feedback needed Further information is requested label Dec 5, 2022
@Zeryther
Copy link

Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feedback needed Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants