fix: avoid "No clang found" when the clang cache is deleted by a parallel request - #6649
Merged
Conversation
Member
Author
|
@skerbis Da nicht so direkt reproduzierbar bei dir, ist es wahrscheinlich nicht so leicht testbar für dich, oder? Dann würde ich es einfach so mergen und hoffen, dass es tatsächlich hilft. |
Contributor
|
@gharlan danke. ja es ist schwer zu testen. |
…llel request `rex_clang::checkCache()` checked the cache file with `is_file()` and read it afterwards. If a parallel request cleared the cache in between, the read failed silently, `rex_file::getCache()` returned its empty default and the clang list stayed empty for the whole request - which surfaces as `LogicException: No clang found.` in `getStartId()`, and as silently wrong results in `exists()`/`getAll()`. Read the file first and fall back to a freshly generated cache if the result is empty. `rex_clang_service::generateCache()` now returns the generated data, so the fallback does not have to read the file again and cannot lose the same race.
gharlan
force-pushed
the
fix-clang-cache-race
branch
from
August 31, 2026 15:14
bcf97c0 to
cdf4931
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6648
Problem
rex_clang::checkCache()used a check-then-read pattern:rex_delete_cache()wipes the whole cache directory. If that happens between theis_file()check and the read,file_get_contents()fails,rex_file::getCache()returns its empty default[]— andcheckCache()still setscacheLoaded = true. The request then runs with zero languages.The visible symptom is
LogicException: No clang found.fromgetStartId(), whichboot.phpevaluates on nearly every request (rex_request('clang', 'int', rex_clang::getStartId())) — hence the reports of the error hitting completely unrelated pages. Less visible, but worse:exists(),get()andgetAll()silently return wrong results in the same situation.Note that the "reading while another request writes" theory from the issue does not apply —
rex_file::put()already writes atomically viatempnam()+rename().Fix
Read the file first and fall back to a freshly generated cache when the result is empty.
rex_clang_service::generateCache()now returns the data it generated, so the fallback does not read the file back from disk and cannot lose the same race a second time. This mirrors the read-first pattern already used by mediapool and structure.As a side effect, an empty or truncated cache file no longer leads to
foreachovernull.The exception in
getStartId()still fires when theclangtable really is empty.Compatibility
generateCache()gained a return value (previously@return void); callers are unaffected.Testing
clang.cache: the cache is regenerated and the languages load correctly.composer phpstan,composer psalm,composer csclean; no baseline changes.