Skip to content

[BUGFIX] Rebuild proxy class removed by concurrent cache flush - #53

Merged
garbast merged 1 commit into
evoWeb:developfrom
sfroemkenjw:bugfix/rebuild-proxy-after-concurrent-flush
Nov 24, 2026
Merged

garbast merged 1 commit into
evoWeb:developfrom
sfroemkenjw:bugfix/rebuild-proxy-after-concurrent-flush

Conversation

@sfroemkenjw

Copy link
Copy Markdown
Contributor

Problem

ClassLoader::loadClass() checks the cache entry with has() and then calls requireOnce():

if (!$this->classCache->has($cacheEntryIdentifier)) {
    $this->classCacheManager->build($cacheEntryIdentifier, $className);
}
$this->classCache->requireOnce($cacheEntryIdentifier);
$return = true;

SimpleFileBackend::requireOnce() returns false if the file is missing. A concurrent cache flush (cache:flush, a deployment or "Flush all caches") can remove the proxy file after has() and before requireOnce(). When that happens the class stays undefined, but loadClass() still returns true. PHP then moves on to the Composer autoloader, which loads the plain base class without the extending classes. No error is raised.

Why 11.1.4 does not cover this

11.1.4 (7912da2) flushes the Extbase cache after building proxy classes. That only helps if the rebuild happens after the broken DataMap was written. With parallel requests the order is often the other way round:

Step Request What happens
1 A has() returns true. A concurrent flush removes the proxy file. requireOnce() returns false, so Composer loads the base Location model without the extending property facility (?Facility).
2 C Rebuilds the proxy file. ClassCacheManager::addFileToCache() flushes the Extbase cache.
3 A Builds the DataMap for Location from the base class, so facility gets Relation::HAS_NONE. DataMapFactory::buildDataMap() writes this DataMap to the shared Extbase cache right away.
4 D Finishes later and writes the ClassSchemata entry in ReflectionService::__destruct(), where the last writer wins. That entry is built from the correct proxy class, which includes facility.
5 All later requests They get the correct class and the correct ClassSchema, but the broken DataMap from the cache.

From step 5 on, DataMapper::getEmptyRelationValue() maps an empty facility to [] instead of null:

DataMapper::thawObjectProperty(): Return value must be of type ?object, array returned

The error stays until the Extbase cache is flushed again. We ran into this in production right after a cache:flush under live traffic (TYPO3 13.4, EXT:events2 with extending models, Extbase cache on the file backend).

How to reproduce

The real window is only a few microseconds wide, so the order of events has to be forced:

  1. Extend a model of another extension with a relation property (e.g. ?Facility).
  2. In ClassLoader::loadClass(), remove the proxy cache entry right before requireOnce().
  3. Let a parallel request rebuild the proxy before the first request builds its DataMap.
  4. Load a record whose relation is empty. You get the TypeError shown above.

Fix

If requireOnce() returns false, build the entry again and require it:

// A concurrent cache flush may remove the cache entry after has() returned true. Without
// the merged file, composer would silently load the base class without the extending classes.
if ($this->classCache->requireOnce($cacheEntryIdentifier) === false) {
    $this->classCacheManager->build($cacheEntryIdentifier, $className);
    $this->classCache->requireOnce($cacheEntryIdentifier);
}

Through the existing 11.1.4 behaviour, the rebuild also flushes the Extbase cache before this request builds its DataMap. We forced the same order of events against the patched version: the DataMap is correct and no error occurs.

Tests

  • New: Tests/Functional/Loader/ClassLoaderTest::loadClassRebuildsCacheEntryRemovedByConcurrentFlush. requireOnce() returns false first and true second, and build() must be called exactly once.
  • The existing loadClass test now also asserts that build() is never called when the entry exists.

All 39 functional tests pass. php-cs-fixer and PHPStan pass as well.

🤖 Generated with Claude Code

@sfroemkenjw
sfroemkenjw changed the base branch from main to develop November 24, 2026 06:49
A concurrent cache flush may delete the proxy file between has() and
requireOnce(). Composer then silently loads the base class without the
extending classes. Rebuild the entry if requireOnce() returns false.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sfroemkenjw
sfroemkenjw force-pushed the bugfix/rebuild-proxy-after-concurrent-flush branch from ed1a9d1 to 80bec12 Compare November 24, 2026 06:51
@garbast
garbast merged commit 6d7dcdd into evoWeb:develop Nov 24, 2026
18 checks passed
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.

2 participants