diff --git a/src/main_thread/decrypt/create_or_load_session.ts b/src/main_thread/decrypt/create_or_load_session.ts index 23587597c2..8bb8cfaab8 100644 --- a/src/main_thread/decrypt/create_or_load_session.ts +++ b/src/main_thread/decrypt/create_or_load_session.ts @@ -82,7 +82,12 @@ export default async function createOrLoadSession( } } - await cleanOldLoadedSessions(loadedSessionsStore, maxSessionCacheSize); + await cleanOldLoadedSessions( + loadedSessionsStore, + // Account for the next session we will be creating + // Note that `maxSessionCacheSize < 0 has special semantic (no limit)` + maxSessionCacheSize <= 0 ? maxSessionCacheSize : maxSessionCacheSize - 1, + ); if (cancelSignal.cancellationError !== null) { throw cancelSignal.cancellationError; // stop here if cancelled since }