Make session cleanup best effort

This commit is contained in:
Chirag Aggarwal
2026-04-06 18:40:01 +05:30
parent d1b3e2ad81
commit f914290198
+16 -5
View File
@@ -742,12 +742,23 @@ Http::shutdown()
return;
}
for ($i = 0; $i < ($count - $sessionLimit); $i++) {
$session = array_shift($sessions);
$dbForProject->deleteDocument('sessions', $session->getId());
}
try {
for ($i = 0; $i < ($count - $sessionLimit); $i++) {
$session = array_shift($sessions);
$dbForProject->purgeCachedDocument('users', $userId);
if (!$session instanceof Document) {
continue;
}
$dbForProject->deleteDocument('sessions', $session->getId());
}
} catch (\Throwable) {
// Session-limit cleanup is best-effort. Concurrent session creation can race with
// older-session deletion, but that should not fail the request that just created a
// valid session for the user.
} finally {
$dbForProject->purgeCachedDocument('users', $userId);
}
});
Http::shutdown()