#110937Page cache lock is released before the page cache entry is persisted, so waiting requests re-render the page
Description
On a page cache miss, PrepareTypoScriptFrontendRendering acquires the exclusive pages lock, so concurrent requests for the same page wait instead of rendering in parallel. After waiting, a request re-reads the page cache and only renders if there is still no entry.
The lock is released in the finally block of PrepareTypoScriptFrontendRendering::process() (line 274) as soon as the inner middleware stack has returned. The page cache entry, however, is not written there: RequestHandler only enqueues it via $cacheDataCollector->enqueueCacheEntry() (line 206), and the outer middleware CacheDataCollectorAttribute persists it after $handler->handle() has returned (line 70 ff.).
So there is a window between “lock released” and “cache entry written”. A waiting request that obtains the lock in this window does not find a cache entry and renders the page itself — again holding the lock. The other waiting requests keep queueing behind it. Depending on timing, a burst of concurrent requests on an expired page turns into a chain of sequential full renderings instead of one.
Steps to reproduce:
1. Frontend page with a noticeable rendering time (several seconds), cached, short lifetime.
2. Wait until the page cache entry has expired (or flush the page cache).
3. Send 10 concurrent identical requests for that page, e.g.:
seq 10 | xargs -P10 -I{} curl -s -o /dev/null -w "%{time_total}\n" https://example.org/page/
4. With config.debug = 1, check the X-TYPO3-Debug-Cache header of each response.
Expected result:
One request renders the page; the other nine wait for the lock and are then served from the page cache entry written by the first one. Response times are roughly “rendering time” for all ten.
Actual result (measured on a staging system, TYPO3 14.3.7):
- 5 of 10 responses have no X-TYPO3-Debug-Cache header, i.e. rendered themselves, with response times 12.1 s / 14.3 s / 17.8 s / 20.1 s / 23.5 s – strictly increasing, i.e. sequential renderings under the lock.
- The other 5 were served from the cache, but from two different entries (different Expires values), i.e. the page was written to the cache more than once.
- With a warm cache, the same 10 concurrent requests take 1.7–2.2 s each.
Impact:
On a busy or attacked site, every expiry of a frequently requested page can block several PHP workers in a row for the full rendering time. We ran into this while hardening a site after an outage caused by a scanner (originally via no_cache=1, which renders under the same lock on every request).
Possible fix:
Persist the page cache entry before the pages lock is released, e.g. write the tsfe-page-cache entry directly in RequestHandler/@PrepareTypoScriptFrontendRendering@ instead of deferring it to CacheDataCollectorAttribute, or release the lock only after the deferred cache entries have been persisted.
Reviews 1
History 14
-
Wolfgang Klinger changed assigned to Wolfgang Klinger <span data-processor="relativetime" data-value="2026-10-09T05:04:48+00:00" > 10/09/26, 05:04 </span>
-
Gerrit Code Review pushed patch set 1 for main to change 96544 status
NewUnder Review <span data-processor="relativetime" data-value="2026-10-09T05:15:40+00:00" > 10/09/26, 05:15 </span> -
Gerrit Code Review pushed patch set 2 for main to change 96544 <span data-processor="relativetime" data-value="2026-10-09T05:16:34+00:00" > 10/09/26, 05:16 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 96544 <span data-processor="relativetime" data-value="2026-10-09T12:41:27+00:00" > 10/09/26, 12:41 </span>