#111429Resolving a page fails with "database is locked" on SQLite in WAL mode when another request writes concurrently
Description
Problem
PageSlugCandidateProvider::getPagesFromDatabaseForCandidates() selects the page candidates and iterates the result with while ($row = $statement->fetchAssociative()). Inside that loop it calls SiteFinder::getSiteByPageId(), which builds a rootline and, on a cold cache, writes the rootline cache. With the default Typo3DatabaseBackend that is a write on the same database connection while the result of the SELECT is still open.
On SQLite in WAL mode this fails as soon as another connection commits a write in between:
Doctrine\DBAL\Exception\LockWaitTimeoutException: An exception occurred while executing a query: SQLSTATE[HY000]: General error: 5 database is locked
The exception is raised in Typo3DatabaseBackend::remove(), called from Typo3DatabaseBackend::set() <- RootlineUtility <- SiteFinder::getSiteByPageId() <- PageSlugCandidateProvider::getPagesFromDatabaseForCandidates().
It fails immediately, a configured busy_timeout has no effect.
Cause
A SELECT statement that has not been read to its end keeps the read transaction of its connection open, and with it the WAL snapshot. This also applies to a result with a single row that has already been fetched. Once another connection commits, a write on the first connection would have to upgrade an outdated snapshot to a write transaction. SQLite refuses that with SQLITE_BUSY_SNAPSHOT (extended result code 517) and does not call the busy handler, because waiting cannot make the snapshot current. Doctrine DBAL maps the error to LockWaitTimeoutException.
Verified outside of TYPO3 with two plain connections (SQLite 3.54, WAL, busy_timeout 120000): connection A fetches one row of a SELECT, connection B commits an INSERT, the following INSERT on connection A fails after 0 seconds. Without the commit of B, or when A fetches all rows first, the write on A succeeds.
How it was found
The Playwright e2e suite runs against one instance on SQLite in WAL mode. With several parallel workers (#111428) the frontend specs failed with “database is locked” whenever another request was writing at the same time. That this code path is the one failing there is an assumption, the functional test below reproduces the path itself.
Reproduction
Functional test on SQLite: switch the connection to WAL mode, use a rootline cache backend that lets a second connection commit a write right before each cache entry is set, then call PageSlugCandidateProvider::getCandidatesForPath().
Solution
Fetch all rows with fetchAllAssociative() before the loop, which closes the result and ends the read transaction before anything is written.
The same code is in 14.3 and 13.4.
Reviews 1
History 03
-
Gerrit Code Review pushed patch set 1 for main to change 97589 status
NewUnder Review <span data-processor="relativetime" data-value="2026-11-12T20:27:20+00:00" > 11/12/26, 20:27 </span> -
Gerrit Code Review pushed patch set 2 for main to change 97589 <span data-processor="relativetime" data-value="2026-11-12T20:28:53+00:00" > 11/12/26, 20:28 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 97589 <span data-processor="relativetime" data-value="2026-11-13T15:33:31+00:00" > 11/13/26, 15:33 </span>