#106507invalidateAllSessionsByUserId method in SessionManager runs out of memory when fe_sessions table has 300k+ entries
Description
In TYPO3\CMS\Core\Session\SessionManager class method invalidateAllSessionsByUserId is called for an example when fe_user password is changed in backend.
If fe_sessions table has 300k+ entries getting all sessions runs out of memory. Increasing memory to 2GB helps but only to a point.
It would be better if only sessions specific for fe_user are fetched instead of $backend->getAll().
foreach ($backend->getAll() as $session) {
if ($userAuthentication !== null) {
if ($session['ses_id'] === $sessionToRenew || $session['ses_id'] === $hashedSessionToRenew) {
$userAuthentication->enforceNewSessionId();
continue;
}
}
if ((int)$session['ses_userid'] === $userId) {
$backend->remove($session['ses_id']);
}
}
This might also be a problem by password recovery, but I did not test that.
Number of sessions in fe_sessions needed for memory issue depends on ses_data size. My issue was with 300k+ entries.
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
Fix this issue
Start the commit message of your patch with this. Add what the patch does, and the versions it goes to in "Releases:". How to create a patch
- Commit message
-
[BUGFIX] invalidateAllSessionsByUserId method in SessionManager runs out of memory when fe_sessions table has 300k+ entries Resolves: #106507 Releases: main
Files 1
History 3
-
B Novak changed is private <span data-processor="relativetime" data-value="2025-04-03T14:06:18+00:00" > 04/03/25, 14:06 </span>
-
Rémy DANIEL commented and changed attached typo3_core_session_getall.patch <span data-processor="relativetime" data-value="2026-06-19T13:52:58+00:00" > 06/19/26, 13:52 </span>
Patch for v11 attached.
Reproduced on v11.5 with ~90k rows in fe_sessions.
Code is the same on v14, so I suppose the issue still occurs.
Sadly, SessionBackendInterface does not define a method to fetch only session attached to a particular user, so all rows are fetched from the backend.
I suppose it’s because some backend do not support getting filtered rows. Session data is stored as json in redis, thus fetching all sessions of a user is not possible.
Note that collectGarbage on RedisBackend also uses getAll to fetch and delete expired sessions.
We could imagine adding getByUserId on the interface, and changing the way data is stored/indexed on Redis. This will breaks existing Redis database or other backend implementations. Or adding this capability with a new interface.
On my instance, I will just patch \TYPO3\CMS\Core\Session\Backend\DatabaseSessionBackend and \TYPO3\CMS\Core\Session\SessionManager::invalidateAllSessionsByUserId.