nuwave / nuwave/lighthouse

Schema cache leaks memory with Laravel Octane

Open
#2,436 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs reproduction
Dominant language
PHP
Stars
3.5k
Forks
468
Avg merge
3h 9m
Merged PRs (30d)
2

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with Laravel Octane, LIGHTHOUSE_CACHE_ENABLE=true, GraphQL queries, and a low PHP memory limit. Compare the reported cache-off and cache-on memory behavior, then inspect bootstrap/cache/lighthouse-schema.php and determine whether Lighthouse or Octane owns the leak. Done means repeated requests no longer cause unbounded memory growth or the reported fatal exhaustion.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, php
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.