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

Schema cache leaks memory with Laravel Octane #2436

Open
adrianszczotkowski opened this issue Aug 15, 2023 · 1 comment
Open

Schema cache leaks memory with Laravel Octane #2436

adrianszczotkowski opened this issue Aug 15, 2023 · 1 comment
Labels
needs reproduction Failing test case needed

Comments

@adrianszczotkowski
Copy link

I do not know where the problem comes from, nuwave/lighthouse or laravel/octane, so I put that in both project issues.

When cache is disabled Laravel Octane runs garbage collector, but on production is enabled (see difference in response times)

When cache is enabled Laravel Octane does not run garbage collector leading to memory exhaustion.

Steps to reproduce

  1. set php memory limit low, to have quicker effect
  2. use laravel/octane
  3. set env LIGHTHOUSE_CACHE_ENABLE=true
  4. run graphql queries

Output/Logs
Cache off
204 OPTIONS /graphql .................................... 61.19 mb 4.94 ms
2023-08-15T07:59:58.195150293Z 200 POST /graphql ..................................... 61.22 mb 212.50 ms
2023-08-15T08:00:28.216507420Z 204 OPTIONS /graphql .................................... 61.19 mb 0.83 ms
2023-08-15T08:00:28.216723441Z 200 POST /graphql ..................................... 64.42 mb 203.90 ms
2023-08-15T08:00:38.223543408Z 204 OPTIONS /graphql .................................... 64.40 mb 3.72 ms
2023-08-15T08:00:38.223710925Z 200 POST /graphql ..................................... 61.00 mb 242.40 ms
2023-08-15T08:00:58.239050868Z 204 OPTIONS /graphql .................................... 60.97 mb 3.60 ms
2023-08-15T08:00:58.239365373Z 200 POST /graphql ..................................... 61.22 mb 226.69 ms
2023-08-15T08:01:28.263939214Z 204 OPTIONS /graphql .................................... 61.19 mb 3.63 ms
2023-08-15T08:01:28.263992024Z 200 POST /graphql ..................................... 61.22 mb 233.63 ms

Cahche On
PHP memory set to 512MB

2023-08-15T07:52:38.117475683Z 200 POST /graphql ..................................... 105.41 mb 30.35 ms
2023-08-15T07:52:38.117477066Z 200 POST /graphql ..................................... 483.94 mb 36.73 ms
2023-08-15T07:53:38.159570346Z 204 OPTIONS /graphql ................................... 483.93 mb 3.71 ms
2023-08-15T07:53:38.159644884Z 204 OPTIONS /graphql ................................... 105.40 mb 3.64 ms
2023-08-15T07:53:38.159775573Z 200 POST /graphql ..................................... 115.33 mb 29.72 ms
2023-08-15T07:53:38.160064231Z 200 POST /graphql ..................................... 493.87 mb 35.12 ms
2023-08-15T07:54:38.199231222Z 204 OPTIONS /graphql ................................... 493.86 mb 3.61 ms
2023-08-15T07:54:38.199262697Z 204 OPTIONS /graphql ................................... 115.33 mb 3.46 ms
2023-08-15T07:54:38.199265135Z 200 POST /graphql ..................................... 125.26 mb 32.50 ms
2023-08-15T07:54:38.199304818Z PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /var/www/html/bootstrap/cache/lighthouse-schema.php on line 6
2023-08-15T07:54:38.199316710Z PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 65536 bytes) in /var/www/html/vendor/symfony/error-handler/Error/FatalError.php on line 14
2023-08-15T07:54:38.199349102Z [mutex.cc : 2374] RAW: Check w->waitp->cond == nullptr failed: Mutex::Fer while waiting on Condition

Lighthouse Version
latest

Laravel Version
latest

@spawnia spawnia changed the title Schema cache when using Laravel Octane Schema cache leaks memory with Laravel Octane Aug 16, 2023
@spawnia spawnia added the needs reproduction Failing test case needed label Aug 16, 2023
@spawnia
Copy link
Collaborator

spawnia commented Aug 16, 2023

There might be insufficient cleanup related to caching. Consider

lighthouse/src/GraphQL.php

Lines 350 to 355 in c28822a

protected function cleanUpAfterExecution(): void
{
BatchLoaderRegistry::forgetInstances();
FieldValue::clear();
$this->errorPool->clear();
}
- perhaps something similar is also required for caching? The schema cache is dealt with in https://github.com/nuwave/lighthouse/blob/master/src/Schema/AST/ASTBuilder.php.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs reproduction Failing test case needed
Projects
None yet
Development

No branches or pull requests

2 participants