From db58b23d519f093686099c145fbec5191feac056 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Mon, 27 Jan 2025 18:44:07 -0300 Subject: [PATCH] regression: do not update logged out sessions (#35041) --- apps/meteor/app/statistics/server/lib/SAUMonitor.ts | 8 +++++++- packages/models/src/models/Sessions.ts | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/meteor/app/statistics/server/lib/SAUMonitor.ts b/apps/meteor/app/statistics/server/lib/SAUMonitor.ts index 32c70ccb29988..056acbb1f1c73 100644 --- a/apps/meteor/app/statistics/server/lib/SAUMonitor.ts +++ b/apps/meteor/app/statistics/server/lib/SAUMonitor.ts @@ -30,6 +30,8 @@ const getUserRoles = mem( { maxAge: 5000 }, ); +const isProdEnv = process.env.NODE_ENV === 'production'; + /** * Server Session Monitor for SAU(Simultaneously Active Users) based on Meteor server sessions */ @@ -143,7 +145,11 @@ export class SAUMonitorClass { projection: { loginToken: 1 }, }); if (!session?.loginToken) { - throw new Error('Session not found'); + if (!isProdEnv) { + throw new Error('Session not found during logout'); + } + logger.error('Session not found during logout', { userId, sessionId }); + return; } await Sessions.logoutBySessionIdAndUserId({ loginToken: session.loginToken, userId }); diff --git a/packages/models/src/models/Sessions.ts b/packages/models/src/models/Sessions.ts index ae0ef369a11ae..9310d103de947 100644 --- a/packages/models/src/models/Sessions.ts +++ b/packages/models/src/models/Sessions.ts @@ -1442,8 +1442,10 @@ export class SessionsRaw extends BaseRaw implements ISessionsModel { const now = new Date(); + const query = { instanceId, sessionId, year, month, day, logoutAt: { $exists: false } }; + return this.updateOne( - { instanceId, sessionId, year, month, day }, + query, { $set: data, $setOnInsert: {