Skip to content

Conversation

@spawnia
Copy link
Collaborator

@spawnia spawnia commented Sep 11, 2025

@thekonz Turns out you were right all along to also use atomic writes for the query cache files in your original pull request.

After deploying the new query cache to production, I saw the following error a couple of times:

TypeError: GraphQL\Utils\AST::fromArray(): Argument #1 ($node) must be of type array, int given, called in /var/www/vendor/nuwave/lighthouse/src/Cache/QueryCache.php on line 152
#56 /vendor/webonyx/graphql-php/src/Utils/AST.php(74): GraphQL\Utils\AST::fromArray
#55 /vendor/nuwave/lighthouse/src/Cache/QueryCache.php(152): Nuwave\Lighthouse\Cache\QueryCache::requireOPcacheFile
#54 /vendor/nuwave/lighthouse/src/Cache/QueryCache.php(118): Nuwave\Lighthouse\Cache\QueryCache::fromHybridOrParse
#53 /vendor/nuwave/lighthouse/src/Cache/QueryCache.php(73): Nuwave\Lighthouse\Cache\QueryCache::fromCacheOrParse
#52 /vendor/nuwave/lighthouse/src/GraphQL.php(287): Nuwave\Lighthouse\GraphQL::parse
...

I believe it comes from concurrent writes to the file.

@spawnia spawnia merged commit 2de0a54 into master Sep 11, 2025
65 checks passed
@spawnia spawnia deleted the use-atomic-file-writes-for-query-cache branch September 11, 2025 08:06
@spawnia
Copy link
Collaborator Author

spawnia commented Sep 11, 2025

@thekonz
Copy link
Collaborator

thekonz commented Sep 11, 2025

i think it is a partial file being read into opcache.

@spawnia
Copy link
Collaborator Author

spawnia commented Sep 11, 2025

Yeah, if the written file is empty or only contains <?php (no return), require returns 1. I suspect what happened is that:

  • two processes A and B ran at the same time
  • process A tries to write the file, the first step for that is that an empty file is created
  • process B sees the empty file and tries to read from it

Now, this change makes sure that the file is filled once it exists at the proper path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants